MySQL實(shí)現(xiàn)免密登錄的三種配置方式
一、示例環(huán)境版本說(shuō)明
操作系統(tǒng)版本centos7.6
[wuhs@test1 mysql]$ cat /etc/redhat-release CentOS Linux release 7.6.1810 (Core)
mysql數(shù)據(jù)庫(kù)版本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、通過(guò)設(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ù)庫(kù)
[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>
此方式最大問(wèn)題是明文存儲(chǔ)密碼,見(jiàn)配置文件各用戶(hù)可見(jiàn),非常的不安全。
2、我們通過(guò)my.cnf來(lái)配置,設(shè)置到~/.my.cnf來(lái)配置免密碼
編輯~/.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ù)庫(kù)
[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>
此種方式也是明文存儲(chǔ),配置方式同第一種,文件為隱藏文件,設(shè)置文件為改用戶(hù)可讀,與第一種方式相比安全性有所提高。經(jīng)驗(yàn)證測(cè)試,~/.my.cnf配置文件優(yōu)先于/etc/my.cnf。
3、通過(guò)mysql_config_editor命令
使用mysql_config_editor命令一個(gè)test標(biāo)簽
[wuhs@test1 mysql]$ mysql_config_editor set -G test -S /tmp/mysql.sock -uroot -p Enter password: [此處輸入root賬戶(hù)密碼]
執(zhí)行如上步驟后生成了隱藏文件.mylogin.cnf,文件類(lèi)型為data,是一個(gè)二進(jìn)制文件
[wuhs@test1 mysql]$ file ~/.mylogin.cnf /home/wuhs/.mylogin.cnf: data
查看該文件,密碼為加密存儲(chǔ)
[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)制文件,且密碼通過(guò)密文存儲(chǔ),安全性最高。
以上就是MySQL免密登錄的三種方式的詳細(xì)內(nèi)容,更多關(guān)于MySQL免密登錄的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
MySQL高效模糊搜索之內(nèi)置函數(shù)locate instr position find_in_set使用詳解
在MySQL中一般進(jìn)行模糊搜索都是使用LIKE配合通配符進(jìn)行查詢(xún)的,在性能上一定的影響,下面給大家分享MYSQL自帶的內(nèi)置模糊搜索函數(shù),除最后一個(gè)外其它三個(gè)性能上要比Like快些2018-09-09MySql獲取某個(gè)字段存在于哪個(gè)表的sql語(yǔ)句
本文為大家詳細(xì)介紹下通過(guò)MySql查詢(xún)某個(gè)字段所在表是哪一個(gè),具體的sql語(yǔ)句如下,感興趣的朋友可以參考下,希望對(duì)大家有所幫助2013-07-07MySql允許遠(yuǎn)程連接如何實(shí)現(xiàn)該功能
這篇文章主要介紹了 MySql允許遠(yuǎn)程連接如何實(shí)現(xiàn)該功能的相關(guān)資料,需要的朋友可以參考下2017-02-02關(guān)于mysql delete的問(wèn)題小結(jié)
關(guān)于mysql delete的問(wèn)題,需要的朋友可以參考下。2011-05-05Mysql數(shù)據(jù)庫(kù)時(shí)間與系統(tǒng)時(shí)間不一致問(wèn)題排查及解決
最近忽然發(fā)現(xiàn)個(gè)問(wèn)題,Mysql數(shù)據(jù)庫(kù)時(shí)間與系統(tǒng)時(shí)間不一致,通過(guò)查找相關(guān)資料終于解決了,下面這篇文章主要給大家介紹了關(guān)于Mysql數(shù)據(jù)庫(kù)時(shí)間與系統(tǒng)時(shí)間不一致問(wèn)題排查及解決的相關(guān)資料,需要的朋友可以參考下2023-06-06