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

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

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

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

    MySQL向表中添加列方法實例

    要在MySQL的表中添加列,我們可以將ALTER命令與add column命令一起使用,下面這篇文章主要給大家介紹了關(guān)于MySQL向表中添加列的相關(guān)資料,文中通過實例代碼介紹的非常詳細(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)行查詢的,在性能上一定的影響,下面給大家分享MYSQL自帶的內(nèi)置模糊搜索函數(shù),除最后一個外其它三個性能上要比Like快些
    2018-09-09
  • MySql獲取某個字段存在于哪個表的sql語句

    MySql獲取某個字段存在于哪個表的sql語句

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

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

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

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

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

    重裝mysql時3306端口被占用的解決方法

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

    MySQL性能瓶頸排查定位實例詳解

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

    MySql允許遠(yuǎn)程連接如何實現(xiàn)該功能

    這篇文章主要介紹了 MySql允許遠(yuǎn)程連接如何實現(xiàn)該功能的相關(guān)資料,需要的朋友可以參考下
    2017-02-02
  • 關(guān)于mysql delete的問題小結(jié)

    關(guān)于mysql delete的問題小結(jié)

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

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

最新評論