MySQL實現(xiàn)免密登錄的三種配置方式
一、示例環(huán)境版本說明
操作系統(tǒng)版本centos7.6
[wuhs@test1 mysql]$ cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core)
mysql數(shù)據(jù)庫版本5.7.32
[wuhs@test1 mysql]$ mysql -V mysql Ver 14.14 Distrib 5.7.32, for el7 (x86_64) using EditLine wrapper
二、MySQL免密登錄方式配置示例
1、通過設(shè)置client標(biāo)簽,直接編輯/etc/my.cnf文件
編輯/etc/my.cnf文件,添加如下代碼
[wuhs@test1 mysql]$ cat /etc/my.cnf [client] user = root password = 123456 port = 3306
配置完成后可以使用mysql命令直接登錄數(shù)據(jù)庫
[wuhs@test1 mysql]$ mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.7.32-log MySQL Community Server (GPL) <br> Copyright ? 2000, 2020, Oracle and/or its affiliates. All rights reserved. <br> Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. <br> Type ‘help;' or ‘\h' for help. Type ‘\c' to clear the current input statement. <br> mysql>
此方式最大問題是明文存儲密碼,見配置文件各用戶可見,非常的不安全。
2、我們通過my.cnf來配置,設(shè)置到~/.my.cnf來配置免密碼
編輯~/.my.cnf文件,添加如下代碼
[wuhs@test1 mysql]$ cat ~/.my.cnf [client] user = root password = 123456 port = 3306
修改my.cnf屬性
#chmod 600 ~/.my.cnf [wuhs@test1 mysql]$ ll ~/.my.cnf -rw-------. 1 wuhs wuhs 51 Dec 29 22:56 /home/wuhs/.my.cnf
配置完成后可以使用mysql命令直接登錄數(shù)據(jù)庫
[wuhs@test1 mysql]$ mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.7.32-log MySQL Community Server (GPL) <br> Copyright ? 2000, 2020, Oracle and/or its affiliates. All rights reserved. <br> Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. <br> Type ‘help;' or ‘\h' for help. Type ‘\c' to clear the current input statement. <br> mysql>
此種方式也是明文存儲,配置方式同第一種,文件為隱藏文件,設(shè)置文件為改用戶可讀,與第一種方式相比安全性有所提高。經(jīng)驗證測試,~/.my.cnf配置文件優(yōu)先于/etc/my.cnf。
3、通過mysql_config_editor命令
使用mysql_config_editor命令一個test標(biāo)簽
[wuhs@test1 mysql]$ mysql_config_editor set -G test -S /tmp/mysql.sock -uroot -p Enter password: [此處輸入root賬戶密碼]
執(zhí)行如上步驟后生成了隱藏文件.mylogin.cnf,文件類型為data,是一個二進(jìn)制文件
[wuhs@test1 mysql]$ file ~/.mylogin.cnf /home/wuhs/.mylogin.cnf: data
查看該文件,密碼為加密存儲
[wuhs@test1 mysql]$ mysql_config_editor print --all [test] user = root password = ***** socket = /tmp/mysql.sock
使用mysql --login-path="標(biāo)簽"登錄
[wuhs@test1 mysql]$ mysql --login-path=test Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 18 Server version: 5.7.32-log MySQL Community Server (GPL) <br> Copyright ? 2000, 2020, Oracle and/or its affiliates. All rights reserved. <br> Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. <br> Type ‘help;' or ‘\h' for help. Type ‘\c' to clear the current input statement. <br> mysql>
第三種方式登錄文件為隱藏的二進(jìn)制文件,且密碼通過密文存儲,安全性最高。
以上就是MySQL免密登錄的三種方式的詳細(xì)內(nèi)容,更多關(guān)于MySQL免密登錄的資料請關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
MySQL高效模糊搜索之內(nèi)置函數(shù)locate instr position find_in_set使用詳解
在MySQL中一般進(jìn)行模糊搜索都是使用LIKE配合通配符進(jìn)行查詢的,在性能上一定的影響,下面給大家分享MYSQL自帶的內(nèi)置模糊搜索函數(shù),除最后一個外其它三個性能上要比Like快些2018-09-09MySql允許遠(yuǎn)程連接如何實現(xiàn)該功能
這篇文章主要介紹了 MySql允許遠(yuǎn)程連接如何實現(xiàn)該功能的相關(guān)資料,需要的朋友可以參考下2017-02-02關(guān)于mysql delete的問題小結(jié)
關(guān)于mysql delete的問題,需要的朋友可以參考下。2011-05-05Mysql數(shù)據(jù)庫時間與系統(tǒng)時間不一致問題排查及解決
最近忽然發(fā)現(xiàn)個問題,Mysql數(shù)據(jù)庫時間與系統(tǒng)時間不一致,通過查找相關(guān)資料終于解決了,下面這篇文章主要給大家介紹了關(guān)于Mysql數(shù)據(jù)庫時間與系統(tǒng)時間不一致問題排查及解決的相關(guān)資料,需要的朋友可以參考下2023-06-06