最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MySQL修改賬號密碼方法大全(小結(jié))

 更新時間:2020年12月18日 09:41:58   作者:kunjian  
這篇文章主要介紹了MySQL修改賬號密碼方法大全(小結(jié)),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧

前言:

在日常使用數(shù)據(jù)庫的過程中,難免會遇到需要修改賬號密碼的情景,比如密碼太簡單需要修改、密碼過期需要修改、忘記密碼需要修改等。本篇文章將會介紹需要修改密碼的場景及修改密碼的幾種方式。

1.忘記 root 密碼

忘記 root 密碼的場景還是比較常見的,特別是自己搭的測試環(huán)境經(jīng)過好久沒用過時,很容易記不得當(dāng)時設(shè)置的密碼。這個時候一般常用的方法是跳過權(quán)限驗(yàn)證,然后更改 root 密碼,之后再啟用權(quán)限驗(yàn)證。以 MySQL 5.7 版本為例簡單講下主要過程:

首先修改配置文件,在[mysqld]部分加上一句:skip-grant-tables ,加上此參數(shù)的目的是跳過權(quán)限驗(yàn)證。然后重啟數(shù)據(jù)庫,數(shù)據(jù)庫再次啟動后,我們就可以不用密碼直接登錄數(shù)據(jù)庫修改密碼了。

# skip-grant-tables 模式下修改root密碼
[root@host ~]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.7.23-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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.

mysql> update mysql.user set authentication_string = password ('xxxxxx') where user = 'root' and host = 'localhost';
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

修改完 root 密碼后,再次去除 skip-grant-tables 參數(shù),然后重啟下數(shù)據(jù)庫即可。

2.幾種修改密碼的方法

除去忘記密碼,可能還有其他情景需要修改密碼,這時候就可以采取普通方式修改密碼了。還是以 MySQL 5.7 版本為例,介紹幾種常用的修改密碼的方法。

使用 alter user 修改

比如如果想更改 testuser 賬號的密碼,我們可以使用 root 賬號登錄,然后執(zhí)行 alter user 命令更改 testuser 賬號的密碼。

mysql> alter user 'testuser'@'%' identified by 'Password1';
Query OK, 0 rows affected (0.01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

使用 SET PASSWORD 命令

使用 SET PASSWORD 修改密碼命令格式為 SET PASSWORD FOR 'username'@'host' = PASSWORD('newpass'); 同樣是使用 root 賬號可修改其他賬號的密碼。

mysql> SET PASSWORD FOR 'testuser'@'%' = PASSWORD('Password2');
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

使用 mysqladmin 修改密碼

使用 mysqladmin 命令修改賬號密碼格式為 mysqladmin -u用戶名 -p舊密碼 password 新密碼

[root@host ~]# mysqladmin -utestuser -pPassword2 password Password3
mysqladmin: [Warning] Using a password on the command line interface can be insecure.
Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.
[root@host ~]# mysql -utestuser -pPassword3
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 2388
Server version: 5.7.23-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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.

mysql> 

直接 update user 表

其實(shí) MySQL 所以的賬號信息都存儲在 mysql.user 表里面,我們也可以直接通過 update user 表來修改密碼。

# 5.7及之后版本
mysql> update mysql.user set authentication_string = password ('Password4') where user = 'testuser' and host = '%';
Query OK, 1 row affected, 1 warning (0.06 sec)
Rows matched: 1 Changed: 1 Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

# 5.6及之前版本
update mysql.user set password=password('新密碼') where user='用戶名' and host='host'; 

3.設(shè)置 login-path 本地快捷登陸

為了防止密碼暴露及忘記密碼,我們還可以設(shè)置 login-path 來實(shí)現(xiàn)在本地不輸密碼快捷登錄。

login-path 是 MySQL 5.6 開始支持的新特性。通過借助 mysql_config_editor 工具將登陸 MySQL 服務(wù)的認(rèn)證信息加密保存在 .mylogin.cnf 文件(默認(rèn)位于用戶主目錄)。MySQL 客戶端工具可通過讀取該加密文件連接 MySQL ,實(shí)現(xiàn)快捷登錄。

假設(shè)我們想配置 root 賬號在本地快捷登錄,可以這么做:

# 執(zhí)行回車后需要輸入一次root密碼
[root@host ~]# mysql_config_editor set --login-path=root -uroot -hlocalhost -p -P3306 
Enter password: 

# 配置完成后可以使用login-path登錄
[root@host ~]# mysql --login-path=root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2919
Server version: 5.7.23-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, 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.

mysql> 

總結(jié):

本篇文章主要介紹了修改數(shù)據(jù)庫賬號密碼的幾種方法,基本涵蓋了所有的場景。這里也提醒下各位,數(shù)據(jù)庫賬號最好限制ip段登錄,密碼盡量復(fù)雜些,最好能夠定期修改,特別是重要的環(huán)境不能有半點(diǎn)馬虎。年底了,安全才是王道。

到此這篇關(guān)于MySQL修改賬號密碼方法大全(小結(jié))的文章就介紹到這了,更多相關(guān)MySQL修改賬號密碼內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • 清空mysql 查詢緩存的可行方法

    清空mysql 查詢緩存的可行方法

    mysql對同一條sql進(jìn)行了緩存,在第二次運(yùn)行時, 瞬間就完成了,若要清除緩存,可通過下面的方法來實(shí)現(xiàn)
    2014-07-07
  • innodb_flush_method取值方法(實(shí)例講解)

    innodb_flush_method取值方法(實(shí)例講解)

    下面小編就為大家?guī)硪黄猧nnodb_flush_method取值方法(實(shí)例講解)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-03-03
  • MySQL查詢倒數(shù)第二條記錄實(shí)現(xiàn)方法

    MySQL查詢倒數(shù)第二條記錄實(shí)現(xiàn)方法

    這篇文章主要介紹了MySQL查詢倒數(shù)第二條記錄實(shí)現(xiàn)方法,本文直接給出代碼實(shí)例,重要部分已經(jīng)加紅提示,需要的朋友可以參考下
    2015-05-05
  • 關(guān)于mysql合并表的詳細(xì)介紹

    關(guān)于mysql合并表的詳細(xì)介紹

    本篇文章是對mysql中的合并表進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
    2013-06-06
  • MySQL幾種更新操作的案例分析

    MySQL幾種更新操作的案例分析

    本文將通過一個用戶賬戶金額更新的案例分析幾種數(shù)據(jù)更新的操作的優(yōu)劣,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2021-10-10
  • mysql中的自連接與join關(guān)聯(lián)

    mysql中的自連接與join關(guān)聯(lián)

    這篇文章主要介紹了mysql中的自連接與join關(guān)聯(lián),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-09-09
  • mysql表類型查詢示例詳解

    mysql表類型查詢示例詳解

    這篇文章主要介紹了mysql表類型查詢示例詳解,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧
    2025-04-04
  • MYSQL拒絕訪問報錯not allowed to connect

    MYSQL拒絕訪問報錯not allowed to connect

    MYSQL拒絕訪問報錯not allowed to connect,下面有個可行的方法,可以在其它任何的主機(jī)上以root身份登錄
    2014-07-07
  • mysql的單列多值存儲實(shí)例詳解

    mysql的單列多值存儲實(shí)例詳解

    數(shù)據(jù)庫市場需要細(xì)分,行式數(shù)據(jù)庫不再滿足所有的需求,而有很多需求需要,下面這篇文章主要給大家介紹了關(guān)于mysql單列多值存儲的相關(guān)資料,文中通過示例代碼介紹介紹的非常詳細(xì),需要的朋友可以參考下
    2022-04-04
  • mysqldump加-w參數(shù)備份數(shù)據(jù)時需要注意的事項(xiàng)

    mysqldump加-w參數(shù)備份數(shù)據(jù)時需要注意的事項(xiàng)

    這篇文章主要介紹了mysqldump加-w參數(shù)備份數(shù)據(jù)時需要注意的事項(xiàng),需要的朋友可以參考下
    2014-06-06

最新評論

天峻县| 昭通市| 永福县| 新泰市| 扎囊县| 甘德县| 永平县| 治多县| 湖口县| 岫岩| 博兴县| 天镇县| 惠水县| 宿州市| 葫芦岛市| 墨脱县| 农安县| 马山县| 五家渠市| 天台县| 合山市| 和平区| 建瓯市| 浦北县| 太湖县| 双峰县| 灌南县| 蓬安县| 乐山市| 九寨沟县| 客服| 永定县| 湘潭市| 山东省| 资中县| 泸州市| 武宣县| 宿州市| 阿克苏市| 马关县| 阜南县|