MySQL-Security
参考文献
- MySQL 8 Cookbook
使用mysql_config_editor
进行无密码认证
1 | mysql_config_editor --help |
-
使用
mysql_config_editor
创建.mylogin.cnf
文件1
2
3
4# mysql_config_editor set --login-path=root_local --host=localhost --user=root --password
Enter password:
# mysql --login-path=root_local
使用X509
设置加密连接
-
验证数据目录中的文件,更新
my.cnf
,重启服务器并检查与SSL
有关的变量1
2
3
4
5
6
7
8
9➜ ll -htr |grep pem
-rw------- 1 _mysql _mysql 1.6K 9 17 2021 ca-key.pem
-rw-r--r-- 1 _mysql _mysql 1.1K 9 17 2021 ca.pem
-rw------- 1 _mysql _mysql 1.6K 9 17 2021 server-key.pem
-rw-r--r-- 1 _mysql _mysql 1.1K 9 17 2021 server-cert.pem
-rw------- 1 _mysql _mysql 1.6K 9 17 2021 client-key.pem
-rw-r--r-- 1 _mysql _mysql 1.1K 9 17 2021 client-cert.pem
-rw------- 1 _mysql _mysql 1.6K 9 17 2021 private_key.pem
-rw-r--r-- 1 _mysql _mysql 452B 9 17 2021 public_key.pem1
2
3
4
5sudo vim /etc/my.cnf
[mysqld]
ssl-ca=/var/lib/mysql/ca.pem
ssl-cert=/var/lib/mysql/server-cert.pem
ssl-key=/var/lib/mysql/server-key.pem1
sudo systemctl restart mysqld
1
mysql> show variables like '%ssl%';
-
将
client-key.pem
,client-cert.pem
文件从服务器的数据目录复制到客户端 -
通过传递
--ssl-cert
和--ssl-key
选项连接到服务器1
mysql --ssl-cert=client.pem --ssl-key=client-key.pem -h <hostname>
-
强制用户只能通过
X509
连接1
mysql> alter user 'username'@'%' require X509;
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 HoleLin's Blog!