mysql配置SSL證書登錄的實(shí)現(xiàn)
前言
國(guó)家等級(jí)保護(hù)三級(jí)安全要求,mysql 的 ssl 需要安全證書加密,這里需要研究一下,選幾個(gè)賬戶演示下即可。mysql 的版本為 8.0.20
一、Mysql 啟用 SSL 配置
1.1 檢查是否開(kāi)啟 ssl
mysql> show variables like '%ssl%'; +--------------------+-----------------+ | Variable_name | Value | +--------------------+-----------------+ | have_openssl | YES | | have_ssl | YES | # 已開(kāi)啟ssl | mysqlx_ssl_ca | | | mysqlx_ssl_capath | | | mysqlx_ssl_cert | | | mysqlx_ssl_cipher | | | mysqlx_ssl_crl | | | mysqlx_ssl_crlpath | | | mysqlx_ssl_key | | | ssl_ca | ca.pem | | ssl_capath | | | ssl_cert | server-cert.pem | | ssl_cipher | | | ssl_crl | | | ssl_crlpath | | | ssl_fips_mode | OFF | | ssl_key | server-key.pem | +--------------------+-----------------+ 17 rows in set (0.56 sec)
1.2 設(shè)置用戶是否使用 SSL 連接
mysql> select ssl_type from user where user = 'dev_fqr' ; +----------+ | ssl_type | +----------+ | | +----------+ 1 row in set (0.05 sec)
默認(rèn)用戶是沒(méi)有使用 SSL 登錄的。
我們可以強(qiáng)制這個(gè)管理用戶使用 SSL 登錄。
alter user 'xxx'@'%' require ssl; 取消ssl驗(yàn)證: alter user 'xxx'@'%' require none;
更改后,該賬戶就無(wú)法登錄了,查看狀態(tài)變成下面這種
mysql> select ssl_type from user where user = 'dev_fqr' ; +----------+ | ssl_type | +----------+ | ANY | +----------+ 1 row in set (0.01 sec)
測(cè)試登錄,本機(jī)無(wú)法直接登錄。
[root@localhost data]# mysql -u dev_fqr -p Enter password: ERROR 2026 (HY000): SSL connection error: SSL is required but the server doesn't support it
遠(yuǎn)程客戶端無(wú)法直接登錄:
1.3 使用 SSL 登錄
要想通過(guò) SSL 登錄,就需要用到下面這幾個(gè)證書,通過(guò) client 證書 與 server 端進(jìn)行校驗(yàn)通過(guò)才能登錄成功。
1) 本機(jī)登錄
在 data 目錄下的三個(gè)文件證書登錄。
[root@localhost data]# mysql -udev_fqr -pDev@fqr2021 --ssl-ca=ca.pem --ssl-cert=client-cert.pem --ssl-key=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 55 Server version: 8.0.22 MySQL Community Server - GPL Copyright (c) 2000, 2020, 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. You are enforcing ssl connection via unix socket. Please consider switching ssl off as it does not make connection via unix socket any more secure. mysql>
2)navicate 遠(yuǎn)程客戶端登錄
把這三個(gè)證書下載下來(lái)
配置證書目錄,即可遠(yuǎn)程訪問(wèn):
二、總結(jié)
因?yàn)闇y(cè)評(píng)的時(shí)候不會(huì)看 JDBC 里面的配置,所以 JDBC 就不改了,不然要改動(dòng)的地方非常的多,具體演示的時(shí)候可以用提前準(zhǔn)備兩個(gè)賬號(hào),到時(shí)候用客戶端連接即可。
目前兩臺(tái) mysql 的ssl 用戶如下:
到此這篇關(guān)于mysql配置SSL證書登錄的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)mysql SSL證書登錄內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
詳解MySQL查詢時(shí)區(qū)分字符串中字母大小寫的方法
MySQL默認(rèn)是不區(qū)分大小寫的,這個(gè)涉及到collate字符集與校驗(yàn)規(guī)則方面的知識(shí),下面會(huì)講到,這里我們就來(lái)詳解MySQL查詢時(shí)區(qū)分字符串中字母大小寫的方法.2016-05-05面試官問(wèn)訂單ID是如何生成的?難道不是MySQL自增主鍵
最近在考慮訂單id怎么生成,下面這篇文章主要給大家介紹了關(guān)于面試官問(wèn)訂單ID是如何生成的?難道不是MySQL自增主鍵的相關(guān)資料,需要的朋友可以參考下2023-02-02解決mysql ERROR 1045 (28000)-- Access denied for user問(wèn)題
這篇文章主要介紹了mysql ERROR 1045 (28000)-- Access denied for user解決方法,需要的朋友可以參考下2018-03-03連接mysql連接超時(shí)報(bào)錯(cuò)問(wèn)題以及解決
這篇文章主要介紹了連接mysql連接超時(shí)報(bào)錯(cuò)問(wèn)題以及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11帶你學(xué)習(xí)MySQL執(zhí)行計(jì)劃
前面文章,我們學(xué)習(xí)了 MySQL 慢日志相關(guān)內(nèi)容,當(dāng)我們篩選得到具體的慢 SQL 后,就要想辦法去優(yōu)化啦。優(yōu)化 SQL 的第一步應(yīng)該是讀懂 SQL 的執(zhí)行計(jì)劃。本篇文章,我們一起來(lái)學(xué)習(xí)下 MySQL explain 執(zhí)行計(jì)劃相關(guān)知識(shí)。2021-05-05