mysql5.7怎么對ssl加密連接-創(chuàng)新互聯(lián)

這篇文章主要講解了“mysql5.7怎么對ssl加密連接”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“mysql5.7怎么對ssl加密連接”吧!

成都創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于成都做網(wǎng)站、網(wǎng)站制作、成都外貿(mào)網(wǎng)站建設(shè)、焉耆網(wǎng)絡(luò)推廣、微信小程序開發(fā)、焉耆網(wǎng)絡(luò)營銷、焉耆企業(yè)策劃、焉耆品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運營等,從售前售中售后,我們都將竭誠為您服務(wù),您的肯定,是我們大的嘉獎;成都創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供焉耆建站搭建服務(wù),24小時服務(wù)熱線:18982081108,官方網(wǎng)址:muchs.cn
該操作在mysql5.7及以后版本,5.6及以前版本不適用該操作
確認(rèn)數(shù)據(jù)庫版本號和端口號
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相關(guān)文件 

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

注意:將上述文件權(quán)限改為mysql所屬

* 重啟 MySQL 服務(wù)

[

root@MySQL ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS! 
Starting MySQL. SUCCESS!

  * 連接MySQL 查看SSL開啟狀態(tài)

     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 + 密碼連接測試

    * 創(chuàng)建用戶并指定 SSL 連接 [ MySQL 5.7后推薦使用create user 方式創(chuàng)建用戶 ]

mysql> create user 'ssl_test'@'%' identified by '123' require SSL;
Query OK, 0 rows affected (0.00 sec)

* 通過密碼連接測試 [ 默認(rèn)采用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 + 密碼 + 密鑰連接

創(chuàng)建用戶并指定 X509 [ SSL+密鑰 ] 連接 [ MySQL 5.7后推薦使用create user 方式創(chuàng)建用戶 ]

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

感謝各位的閱讀,以上就是“mysql5.7怎么對ssl加密連接”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對mysql5.7怎么對ssl加密連接這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!

當(dāng)前題目:mysql5.7怎么對ssl加密連接-創(chuàng)新互聯(lián)
文章轉(zhuǎn)載:http://muchs.cn/article2/deidoc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計、品牌網(wǎng)站設(shè)計、用戶體驗商城網(wǎng)站、品牌網(wǎng)站制作、網(wǎng)站導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)