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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 使用 SSL 加密的 JDBC 連線 SAP HANA 資料庫加密JDBC資料庫
- MySQL 5.7配置SSL連線MySql
- MySQL SSL連線問題MySql
- Ubuntu18.04下安裝Docker並配置SSL證書加密遠端連線UbuntuDocker加密
- 11 配置加密連線加密
- centos無法建立ssl連線CentOS
- Netty 實現SSL安全連線(wss://)Netty
- SSL連線,搭建網路安全道路
- 技術分享 | MySQL : SSL 連線淺析MySql
- TLS加密遠端連線DockerTLS加密Docker
- wget下載提示:無法建立SSL連線wget
- Akka-CQRS(10)- gRPC on SSL/TLS 安全連線RPCTLS
- RabbitMQ開啟SSL與SpringBoot連線測試MQSpring Boot
- raw.githubusercontent.com 無法建立 SSL 連線Github
- [20210428]資料庫連線加密.txt資料庫加密
- Python 連線 Minio 報錯:[SSL: WRONG_VERSION_NUMBER]Python
- golang連線sm3認證加密Golang加密
- 基於 Apaache 的 laravel-websocket SSL配置(wss連線)LaravelWeb
- 執行wget命令,出錯:無法建立 SSL 連線。wget
- 有關https的SSL加密方式HTTP加密
- 清除 Windows 上的 SSL 快取通常是為了解決與 SSL 證書或加密連線相關的問題。你可以按照以下步驟來清除 Windows 上的 SSL 快取:Windows快取加密
- 使用 Apache 反向代理來配置 Laravel-Websocket SSL(WSS 連線)ApacheLaravelWeb
- 20.7 OpenSSL 套接字SSL加密傳輸加密
- HTTPS計算機網路SSL加密HTTP計算機網路加密
- nginx配置ssl加密(單/雙向認證、部分https) – HTTPS SSL 教程Nginx加密HTTP
- JDBC無法用SSL連線SqlServer2008的解決方法JDBCSQLServer
- linux離線安裝mysql5.7LinuxMySql
- MySQL5.7 InnoDB線上DDL操作MySql
- SSL_1758【連通圖】
- win10系統foxmail ssl連線出錯errorcode:5怎麼辦Win10AIError
- SSL證書的加密演算法有哪些?加密演算法
- 內連線、左連線、右連線
- 連線 MySQL 8.0 時,加密方式不相容的解決方法MySql加密
- SSL連線分為兩個階段:握手和資料傳輸階段
- 哪些IP SSL證書支援IP地址https加密呢?HTTP加密
- MYSQL語法:左連線、右連線、內連線、全外連線MySql
- 案例:配置apache和nginx的SSL加密傳輸協議ApacheNginx加密協議
- 來此加密便宜的多域名SSL證書申請加密