字符集--應用顯示亂碼
1、使用gbk編碼,gbk連接,數(shù)據(jù)插入
gbk查詢都正常輸出,utf8查詢正常輸出。
2、使用gbk編碼,utf8連接,數(shù)據(jù)插入
utf8查詢輸出亂碼,gbk查詢輸出亂碼。
3、使用utf8編碼,gbk連接,數(shù)據(jù)插入
gbk查詢代碼異常('gbk' codec can't decode bytes in position),utf8查詢亂碼。
4、使用utf8編碼,utf8連接,數(shù)據(jù)插入
utf8查詢輸出正常,gbk查詢輸出、正常。
字符集--client顯示亂碼
查看Session的字符集
show variables like '%char%';
設置Session的字符集
set names [期望字符集]
亂碼原因
- 數(shù)據(jù)本身亂碼
- client字符集和字符編碼不一致
字符集--數(shù)據(jù)遷移
utf8 表--> utf8表
gbk 表--> utf8表
utf8 表--> gbk表
utf8表 --> latin1表
gbk表 --> latin1表
字符集--備份恢復
既有utf8表,又有g(shù)bk表時,使用binary備份恢復。
字符集變更使用邏輯備份恢復方式,DDL可能導致數(shù)據(jù)丟失。
跨版本升級采用邏輯備份恢復。
字符集 -- 規(guī)范化
統(tǒng)一一種字符集
- 避免開發(fā)混亂
- 避免DB數(shù)據(jù)亂碼
- 便于規(guī)?;\維
國際化
- 使用unicode(utf8)
- utf8mb4 --> utf8
權(quán)限安全 -- 權(quán)限管理
- 空密碼、弱密碼: 全部清理,隨機生成密碼。
- 明文密碼: 統(tǒng)一配置管理,獲取用戶密碼。白屏化,操作流程化
- 最小權(quán)限原則: 開放最小DB訪問權(quán)限,最小系統(tǒng)權(quán)限,滿足需求即可。
- 管理和應用分離: DBA管理和應用賬號嚴格分離,不同應用單獨賬號。
- 歷史操作: 刪除數(shù)據(jù)庫相關(guān)的歷史操作記錄。cat /dev/null > ~/.mysql_history
權(quán)限安全 -- 強制訪問控制
強制訪問控制(MAC)是系統(tǒng)強制主體服從訪問控制策略。與自主訪問控制(DAC)基于系統(tǒng)實體身份及其到系統(tǒng)資源的接入授權(quán)方式,共同保證用戶的權(quán)限。
實現(xiàn)策略:
1、創(chuàng)建系統(tǒng)表 定義用戶的強制訪問權(quán)限管理表。
2、修改用戶認證邏輯 在sql_acl.cc中修改用戶驗證邏輯,檢查強制訪問權(quán)限管理表,是否符合用戶認證要求。
權(quán)限安全 -- 安全審計
審計用戶行為
審計操作內(nèi)容
權(quán)限安全 -- 網(wǎng)絡安全
SSL安全套接字加密傳輸
MySQL數(shù)據(jù)庫內(nèi)網(wǎng)訪問
跨區(qū)域網(wǎng)絡隔離
參考資料
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