openssl genrsa 2048 > ca-key.pem
openssl req -new -x509 -nodes -days 3600 \
-key ca-key.pem -out ca.pem
server-cert.pem = public key, server-key.pem = private key
openssl req -newkey rsa:2048 -days 3600 \
-nodes -keyout server-key.pem -out server-req.pem
openssl rsa -in server-key.pem -out server-key.pem
openssl x509 -req -in server-req.pem -days 3600 \
-CA ca.pem -CAkey ca-key.pem -set_serial 01 -out server-cert.pem
client-cert.pem = public key, client-key.pem = private key
openssl req -newkey rsa:2048 -days 3600 \
-nodes -keyout client-key.pem -out client-req.pem
openssl rsa -in client-key.pem -out client-key.pem
openssl x509 -req -in client-req.pem -days 3600 \
-CA ca.pem -CAkey ca-key.pem -set_serial 01 -out client-cert.pem
openssl verify -CAfile ca.pem server-cert.pem client-cert.pem
[mysqld]
ssl-ca=/home/mysql/sslconfig/ca.pem
ssl-cert=/home/mysql/sslconfig/server-cert.pem
ssl-key=/home/mysql/sslconfig/server-key.pem
说明:pem配置文件中在test目录下有,但是最好自己生成
/home/mysql/mysql-5.5.35-linux2.6-x86_64/mysql-test/std_data
/etc/init.d/mysqld restart
SHOW VARIABLES LIKE 'have_%ssl';
SHOW VARIABLES LIKE '%ssl%';
如果为yes,表示服务端已经开启SSL
查看服务ssl等状态
SHOW STATUS LIKE 'Ssl_cipher';
STATUS或者\s
SSL: Cipher in use is DHE-RSA-AES256-SHA表示客户端已经 使用SSL连接
客户端无SSL登陆:
mysql -uroot -pzdh1234 或者 mysql -uroot -pzdh1234 --ssl=0
客户端开启SSL登陆:
mysql -uroot -hlocalhost -pzdh1234 --ssl-ca=/home/mysql/sslconfig/ca.pem
GRANT ALL PRIVILEGES ON . TO 'ssluser'@'%' IDENTIFIED BY 'zdh1234' REQUIRE SSL;
本机登陆需要单独新增localhost
GRANT ALL PRIVILEGES ON . TO 'ssluser'@'localhost' IDENTIFIED BY 'zdh1234' REQUIRE SSL;
查看用户:
select host,user,password from mysql.user;
修改密码,需要重启mysql:
update user set password=password("zdh1234") where user="root" and host='zdh-11';
客户端无SSL登陆:
mysql -ussluser -pzdh1234
返回错误:ERROR 1045 (28000): Access denied for user 'ssluser'@'localhost' (using password: YES)
客户端开启SSL登陆:
mysql -ussluser -hlocalhost -pzdh1234 \
--ssl-ca=/home/mysql/sslconfig/ca.pem
如果不填密码或者--ssl-ca都无法登陆
mysql -ussluser -hlocalhost -pzdh1234 \
--ssl-cert=/home/mysql/sslconfig/client-cert.pem \
--ssl-key=/home/mysql/sslconfig/client-key.pem
mysql -ussluser -hlocalhost -pzdh1234 \
--ssl-ca=/home/mysql/sslconfig/ca.pem \
--ssl-cert=/home/mysql/sslconfig/client-cert.pem \
--ssl-key=/home/mysql/sslconfig/client-key.pem
由于创建server使用的服务器域名为zdh-11
校验失败,无法登陆:
mysql -uroot -hlocalhost -pzdh1234 --ssl-ca=/home/mysql/sslconfig/ca.pem --ssl-verify-server-cert
校验成功,可以登陆:
mysql -uroot -hzdh-11 -pzdh1234 --ssl-ca=/home/mysql/sslconfig/ca.pem --ssl-verify-server-cert