欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

MySQL實(shí)現(xiàn)免密登錄的三種配置方式

 更新時(shí)間:2024年03月28日 11:12:43   作者:恒悅sunsite  
我們登錄MySQL的時(shí)候有時(shí)候會(huì)忘記root密碼,這時(shí)我們需要免密登錄,所以這篇文章給大家介紹了MySQL免密登錄的三種方式,文章通過(guò)是示例代碼給出了詳細(xì)的配置方案,需要的朋友可以參考下

一、示例環(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向表中添加列方法實(shí)例

    MySQL向表中添加列方法實(shí)例

    要在MySQL的表中添加列,我們可以將ALTER命令與add column命令一起使用,下面這篇文章主要給大家介紹了關(guān)于MySQL向表中添加列的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-06-06
  • MySQL高效模糊搜索之內(nèi)置函數(shù)locate instr position find_in_set使用詳解

    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-09
  • MySql獲取某個(gè)字段存在于哪個(gè)表的sql語(yǔ)句

    MySql獲取某個(gè)字段存在于哪個(gè)表的sql語(yǔ)句

    本文為大家詳細(xì)介紹下通過(guò)MySql查詢(xún)某個(gè)字段所在表是哪一個(gè),具體的sql語(yǔ)句如下,感興趣的朋友可以參考下,希望對(duì)大家有所幫助
    2013-07-07
  • MySQL日期格式以及日期函數(shù)舉例詳解

    MySQL日期格式以及日期函數(shù)舉例詳解

    這篇文章主要給大家介紹了關(guān)于MySQL日期格式及日期函數(shù)的相關(guān)資料,日期在數(shù)據(jù)庫(kù)中是一個(gè)常見(jiàn)且重要的數(shù)據(jù)類(lèi)型,在MySQL中我們可以使用各種函數(shù)和格式化選項(xiàng)來(lái)處理和顯示日期,需要的朋友可以參考下
    2023-11-11
  • MYSQL函數(shù)的使用梳理

    MYSQL函數(shù)的使用梳理

    本篇文章講解是是MySQL的函數(shù)方法,涵蓋所有的MySQL常見(jiàn)的方法,MySQL函數(shù),是一種控制流程函數(shù),屬于數(shù)據(jù)庫(kù)用語(yǔ)言,以下列出了這些函數(shù)的說(shuō)明
    2022-05-05
  • 重裝mysql時(shí)3306端口被占用的解決方法

    重裝mysql時(shí)3306端口被占用的解決方法

    如果在安裝mysql中出現(xiàn)3306端口不能使用,已經(jīng)被占用的過(guò)程,則需要將該端口號(hào)的進(jìn)程釋放即可,所以本文給大家介紹了重裝mysql時(shí)3306端口被占用的解決方法,需要的朋友可以參考下
    2024-02-02
  • MySQL性能瓶頸排查定位實(shí)例詳解

    MySQL性能瓶頸排查定位實(shí)例詳解

    這篇文章主要介紹了MySQL性能瓶頸排查定位的方法,結(jié)合實(shí)例形式詳細(xì)分析了MySQL排查性能瓶頸問(wèn)題的步驟與相關(guān)技巧,需要的朋友可以參考下
    2016-04-04
  • MySql允許遠(yuǎn)程連接如何實(shí)現(xiàn)該功能

    MySql允許遠(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)題小結(jié)

    關(guān)于mysql delete的問(wèn)題,需要的朋友可以參考下。
    2011-05-05
  • Mysql數(shù)據(jù)庫(kù)時(shí)間與系統(tǒng)時(shí)間不一致問(wèn)題排查及解決

    Mysql數(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

最新評(píng)論