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=/data Generating 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 restart Shutting 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=0 mysql: [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' --ssl mysql: [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 12 Server 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 its affiliates. Other names may be trademarks of their respective owners. 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: 12 Current database: Current user: ssl_test@192.168.60.129 SSL: Cipher in use is DHE-RSA-AES256-SHA Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.7.18 MySQL Community Server (GPL) Protocol version: 10 Connection: 192.168.60.129 via TCP/IP Server characterset: latin1 Db characterset: latin1 Client characterset: utf8 Conn. characterset: utf8 TCP port: 3306 Uptime: 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=0 mysql: [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' --ssl mysql: [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 21 Server 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 its affiliates. Other names may be trademarks of their respective owners. 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: 21 Current database: Current user: wang@192.168.60.129 SSL: Cipher in use is DHE-RSA-AES256-SHA Current pager: stdout Using outfile: '' Using delimiter: ; Server version: 5.7.18 MySQL Community Server (GPL) Protocol version: 10 Connection: 192.168.60.129 via TCP/IP Server characterset: latin1 Db characterset: latin1 Client characterset: utf8 Conn. characterset: utf8 TCP port: 3306 Uptime: 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
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30317998/viewspace-2659090/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- RDSSQLServer設定SSL加密連線SQLServer加密
- 配置postfix和dovecot啟用SSL以加密連線加密
- 使用 SSL 加密的 JDBC 連線 SAP HANA 資料庫加密JDBC資料庫
- proxool連線池如何使用SSL方式連線?
- MySQL 5.7配置SSL連線MySql
- MySQL SSL連線問題MySql
- mysql之使用SSL連線MySql
- 安全連線方式ssl(轉)
- SSL為Windows server 2008 IIS7進行加密連線WindowsServer加密
- centos無法建立ssl連線CentOS
- 轉-配置openldap使用SSL連線LDA
- 11 配置加密連線加密
- 加密連線工具Cryptcat加密
- oledb連線加密access加密
- SSL連線,搭建網路安全道路
- MySQL 使用 SSL 連線(附 Docker 例子)MySqlDocker
- mysql建立ssl安全連線的配置MySql
- SSL連線建立過程分析(1)
- FreeBSD安全連線方式SSL(轉)
- Ubuntu18.04下安裝Docker並配置SSL證書加密遠端連線UbuntuDocker加密
- 技術分享 | MySQL : SSL 連線淺析MySql
- Netty 實現SSL安全連線(wss://)Netty
- 【小知識學習】(Securesocketlayer)SSL連線
- TLS加密遠端連線DockerTLS加密Docker
- 使用 ProxySQL 改進 MySQL SSL 的連線效能MySql
- 使用wget提示無法建立SSL連線wget
- JSSE裡怎麼用一個SSL連線既傳輸未經加密的資料又傳輸加密的資料呀?JS加密
- Akka-CQRS(10)- gRPC on SSL/TLS 安全連線RPCTLS
- wget下載提示:無法建立SSL連線wget
- golang連線sm3認證加密Golang加密
- RabbitMQ開啟SSL與SpringBoot連線測試MQSpring Boot
- raw.githubusercontent.com 無法建立 SSL 連線Github
- 基於 Apaache 的 laravel-websocket SSL配置(wss連線)LaravelWeb
- 使用ssh tunnels加密連線oracle資料庫加密Oracle資料庫
- 執行wget命令,出錯:無法建立 SSL 連線。wget
- Python 連線 Minio 報錯:[SSL: WRONG_VERSION_NUMBER]Python
- 使用 Apache 反向代理來配置 Laravel-Websocket SSL(WSS 連線)ApacheLaravelWeb
- 關於weget “無法建立SSL連線”的解決方法