美文网首页
5.MySQL字符集和权限安全

5.MySQL字符集和权限安全

作者: pcliuyang | 来源:发表于2016-05-19 13:41 被阅读73次

    字符集--应用显示乱码

    1、使用gbk编码,gbk连接,数据插入
    gbk查询都正常输出,utf8查询正常输出。
    2、使用gbk编码,utf8连接,数据插入
    utf8查询输出乱码,gbk查询输出乱码。
    3、使用utf8编码,gbk连接,数据插入
    gbk查询代码异常('gbk' codec can't decode bytes in position),utf8查询乱码。
    4、使用utf8编码,utf8连接,数据插入
    utf8查询输出正常,gbk查询输出、正常。


    字符集--client显示乱码

    查看Session的字符集

    show variables like '%char%';  
    

    设置Session的字符集

    set names [期望字符集]
    

    乱码原因

    • 数据本身乱码
    • client字符集和字符编码不一致

    字符集--数据迁移

    utf8 表--> utf8表
    gbk 表--> utf8表
    utf8 表--> gbk表
    utf8表 --> latin1表
    gbk表 --> latin1表


    字符集--备份恢复

    既有utf8表,又有gbk表时,使用binary备份恢复。
    字符集变更使用逻辑备份恢复方式,DDL可能导致数据丢失。
    跨版本升级采用逻辑备份恢复。


    字符集 -- 规范化

    统一一种字符集

    • 避免开发混乱
    • 避免DB数据乱码
    • 便于规模化运维

    国际化

    • 使用unicode(utf8)
    • utf8mb4 --> utf8

    权限安全 -- 权限管理

    • 空密码、弱密码: 全部清理,随机生成密码。
    • 明文密码: 统一配置管理,获取用户密码。白屏化,操作流程化
    • 最小权限原则: 开放最小DB访问权限,最小系统权限,满足需求即可。
    • 管理和应用分离: DBA管理和应用账号严格分离,不同应用单独账号。
    • 历史操作: 删除数据库相关的历史操作记录。cat /dev/null > ~/.mysql_history

    权限安全 -- 强制访问控制

    强制访问控制(MAC)是系统强制主体服从访问控制策略。与自主访问控制(DAC)基于系统实体身份及其到系统资源的接入授权方式,共同保证用户的权限。
    实现策略:
    1、创建系统表 定义用户的强制访问权限管理表。
    2、修改用户认证逻辑 在sql_acl.cc中修改用户验证逻辑,检查强制访问权限管理表,是否符合用户认证要求。


    权限安全 -- 安全审计

    审计用户行为
    审计操作内容


    权限安全 -- 网络安全

    SSL安全套接字加密传输
    MySQL数据库内网访问
    跨区域网络隔离


    参考资料

    1、《Globalization》
    http://dev.mysql.com/doc/refman/5.5/en/globalization.html
    2、《Security》
    http://dev.mysql.com/doc/refman/5.5/en/security.html
    3、《MySQL Security Best Practices》
    http://www.greensql.com/content/mysql-security-best-practices-hardening-mysql-tips
    4、《Security in MySQL》
    http://downloads.mysql.com/docs/mysql-security-excerpt-5.1-en.pdf
    5、《Development and Implementation of Mandatory Access Control Policy for RDBMS MySQL 》
    http://www.slideshare.net/dnkolegov/kolegov-phdaysys2013eng
    6、《Answers: unix - implementation of mandatory access control in mysql 》
    http://www.windowslinuxosx.com/q/answers-implementation-of-mandatory-access-control-in-mysql-724059.html
    7、《MySQL Enterprise Audit》
    http://www.mysql.com/products/enterprise/audit.html
    8、《Writing Audit Plugins》
    http://docs.oracle.com/cd/E17952_01/refman-5.5-en/writing-audit-plugins.html
    9、《MySQL Audit Plugin now available in Percona Server 5.5 and 5.6》
    http://www.mysqlperformanceblog.com/2014/05/07/mysql-audit-plugin-now-available-in-percona-server-5-5-and-5-6/
    10、《mcafee/mysql-audit》
    https://github.com/mcafee/mysql-audit
    11、《HengWang/mysql-audit》
    https://github.com/HengWang/mysql-audit

    相关文章

      网友评论

          本文标题:5.MySQL字符集和权限安全

          本文链接:https://www.haomeiwen.com/subject/pwkgrttx.html