mysql5.7怎么对ssl加密连接
发表于:2025-11-12 作者:千家信息网编辑
千家信息网最后更新 2025年11月12日,这篇文章主要讲解了"mysql5.7怎么对ssl加密连接",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"mysql5.7怎么对ssl加密连接"吧!该操作
千家信息网最后更新 2025年11月12日mysql5.7怎么对ssl加密连接注意:将上述文件权限改为mysql所属
这篇文章主要讲解了"mysql5.7怎么对ssl加密连接",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"mysql5.7怎么对ssl加密连接"吧!
该操作在mysql5.7及以后版本,5.6及以前版本不适用该操作
确认数据库版本号和端口号
mysql> select version();+-----------+| version() |+-----------+| 5.7.19 |+-----------+1 row in set (0.00 sec)
mysql> show variables like 'have%ssl%';+---------------+----------+| Variable_name | Value |+---------------+----------+| have_openssl | DISABLED || have_ssl | DISABLED |+---------------+----------+2 rows in set (0.02 sec)
mysql> show variables like 'port';+---------------+-------+| Variable_name | Value |+---------------+-------+| port | 3306 |+---------------+-------+1 row in set (0.01 sec)
mysql> show variables like 'datadir';+---------------+-------------------+| Variable_name | Value |+---------------+-------------------+| datadir | /data|+---------------+-------------------+1 row in set (0.01 sec)
1. SSL配置
* 利用自带工具生成SSL相关文件
root@MySQL ~]# /usr/local/mysql/bin/mysql_ssl_rsa_setup --datadir=/dataGenerating a 2048 bit RSA private key..........................................................................+++.....+++writing new private key to 'ca-key.pem'-----Generating a 2048 bit RSA private key.......................................................................................................................................................................+++...+++writing new private key to 'server-key.pem'-----Generating a 2048 bit RSA private key.....................+++...........................................+++writing new private key to 'client-key.pem'-----
* 查看生成的SSL文件
[root@MySQL ~]# ls -l /data/mysql_data/*.pem-rw------- 1 root root 1679 Jun 24 20:54 /data/ca-key.pem-rw-r--r-- 1 root root 1074 Jun 24 20:54 /data/ca.pem-rw-r--r-- 1 root root 1078 Jun 24 20:54 /data/client-cert.pem-rw------- 1 root root 1675 Jun 24 20:54 /data/client-key.pem-rw------- 1 root root 1675 Jun 24 20:54 /data/private_key.pem-rw-r--r-- 1 root root 451 Jun 24 20:54 /data/public_key.pem-rw-r--r-- 1 root root 1078 Jun 24 20:54 /data/server-cert.pem-rw------- 1 root root 1675 Jun 24 20:54 /data/server-key.pem
注意:将上述文件权限改为mysql所属
* 重启 MySQL 服务
[
root@MySQL ~]# /etc/init.d/mysqld restartShutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS!
* 连接MySQL 查看SSL开启状态
have_openssl 与 have_ssl 值都为YES表示ssl开启成功
mysql> show variables like 'have%ssl%';+---------------+-------+| Variable_name | Value |+---------------+-------+| have_openssl | YES || have_ssl | YES |+---------------+-------+2 rows in set (0.03 sec)
SSL + 密码连接测试
* 创建用户并指定 SSL 连接 [ MySQL 5.7后推荐使用create user 方式创建用户 ]
mysql> create user 'ssl_test'@'%' identified by '123' require SSL;Query OK, 0 rows affected (0.00 sec)
* 通过密码连接测试 [ 默认采用SSL连接,需要指定不使用SSL连接 ]
[root@MySQL ~]# mysql -h 192.168.60.129 -ussl_test -p'123' --ssl=0mysql: [Warning] Using a password on the command line interface can be insecure.ERROR 1045 (28000): Access denied for user 'ssl_test'@'192.168.60.129' (using password: YES)
* 通过 SSL + 密码 连接测试
SSL: Cipher in use is DHE-RSA-AES256-SHA 表示通过SSL连接
[root@MySQL ~]# mysql -h 192.168.60.129 -ussl_test -p'123' --sslmysql: [Warning] Using a password on the command line interface can be insecure.WARNING: --ssl is deprecated and will be removed in a future version. Use --ssl-mode instead.Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 12Server version: 5.7.18 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> \s--------------mysql Ver 14.14 Distrib 5.7.18, for linux-glibc2.5 (x86_64) using EditLine wrapper Connection id: 12Current database: Current user: ssl_test@192.168.60.129SSL: Cipher in use is DHE-RSA-AES256-SHACurrent pager: stdoutUsing outfile: ''Using delimiter: ;Server version: 5.7.18 MySQL Community Server (GPL)Protocol version: 10Connection: 192.168.60.129 via TCP/IPServer characterset: latin1Db characterset: latin1Client characterset: utf8Conn. characterset: utf8TCP port: 3306Uptime: 7 min 34 sec Threads: 1 Questions: 29 Slow queries: 0 Opens: 112 Flush tables: 1 Open tables: 105 Queries per second avg: 0.063--------------SSL + 密码 + 密钥连接
创建用户并指定 X509 [ SSL+密钥 ] 连接 [ MySQL 5.7后推荐使用create user 方式创建用户 ]
mysql> create user 'wang'@'%' identified by '123' require wang;Query OK, 0 rows affected (0.00 sec)
通过密码连接测试
[root@MySQL ~]# mysql -h 192.168.60.129 -uwang -p'123' --ssl=0mysql: [Warning] Using a password on the command line interface can be insecure.ERROR 1045 (28000): Access denied for user 'wang'@'192.168.60.129' (using password: YES)
* 通过 SSL +密码 连接测试
[root@MySQL ~]# mysql -h 192.168.60.129 -uwang-p'123' --sslmysql: [Warning] Using a password on the command line interface can be insecure.ERROR 1045 (28000): Access denied for user 'wang'@'192.168.60.129' (using password: YES)
* 通过 SSL + 密码+密钥连接测试
SSL: Cipher in use is DHE-RSA-AES256-SHA 表示通过SSL连接
[root@MySQL ~]# mysql -h 192.168.60.129 -uwang -p'123' --ssl-cert=/data/client-cert.pem --ssl-key=/data/client-key.pem mysql: [Warning] Using a password on the command line interface can be insecure.Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 21Server version: 5.7.18 MySQL Community Server (GPL) Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> \s--------------mysql Ver 14.14 Distrib 5.7.18, for linux-glibc2.5 (x86_64) using EditLine wrapper Connection id: 21Current database: Current user: wang@192.168.60.129SSL: Cipher in use is DHE-RSA-AES256-SHACurrent pager: stdoutUsing outfile: ''Using delimiter: ;Server version: 5.7.18 MySQL Community Server (GPL)Protocol version: 10Connection: 192.168.60.129 via TCP/IPServer characterset: latin1Db characterset: latin1Client characterset: utf8Conn. characterset: utf8TCP port: 3306Uptime: 18 min 27 sec Threads: 1 Questions: 40 Slow queries: 0 Opens: 118 Flush tables: 1 Open tables: 111 Queries per second avg: 0.036
感谢各位的阅读,以上就是"mysql5.7怎么对ssl加密连接"的内容了,经过本文的学习后,相信大家对mysql5.7怎么对ssl加密连接这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!
密码
测试
加密
用户
密钥
文件
版本
学习
内容
方式
推荐
生成
成功
口号
就是
工具
思路
情况
所属
数据
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
联想服务器的操作系统
公安机关的网络安全工作
数据库查询返回的是什么
学生会网络技术部年终总结
网络安全检查成立领导小组
大话西游ol 服务器联赛
阿里数据库开源代码
肇庆自主可控软件开发批发价格
学了网络安全有哪些收获
广东征睿网络技术
软件开发工程师的压力
长治网络技术厂家报价
韩国vpn代理服务器
部队网络安全主题演讲
软件开发公司创业成功几率
湖北网络安全网
内网软件开发
量子软件开发平台
数据库开发 版本控制
软件开发工具 2013
剑三链接服务器失败
ogg数据库全称
工业机器人软件开发平台
政务网网络安全不通
网络安全渗透授权
作文网络安全400
网络安全建设关系到国家安全
无线网络技术的应用领域
网络安全个人自查报告表
新乡中隆网络技术有限公司好吗