這篇文章主要介紹了MySQL修改賬號密碼方法大全(小結),改賬文中通過(guò)示例代碼介紹??的號密非常詳細,對大家的碼方學(xué)習或者工作具有一定的參考學(xué)習價(jià)值,需要的改賬朋友們下面隨著(zhù)小編來(lái)一起學(xué)習學(xué)習吧
前言:
在日常使用數據庫的過(guò)程中,難免(′ω`*)會(huì )遇到需要修改賬號密碼的號密情景,比如密碼太簡(jiǎn)單需要修改、碼方密碼過(guò)期需要修改、改賬忘記密碼需要修改等。號密本篇文章將會(huì )介紹需要修改密碼的碼方場(chǎng)景及修改密碼的(′_`)幾種方式。
1.忘記 root 密碼
忘記 root 密碼的改賬場(chǎng)景還是比較常見(jiàn)的,特別是號密自己搭的測試環(huán)境經(jīng)過(guò)好久沒(méi)用過(guò)時(shí),很容易記不得當時(shí)設置(′?`*)的碼方密碼。這個(gè)時(shí)候一般常用的改賬方法??是跳過(guò)權限驗證,然后更改 root 密碼,號密之后再啟用權限驗證。碼方??以 MySQL 5.7 版本為例簡(jiǎn)單講下主要過(guò)程:
首先修改配(′ω`)置文件,在[mysqld]部分加上(shang)一句:skip-grant-tables ,加上此參數的目的是跳過(guò)權限驗證。然后重啟數據(′_ゝ`)庫,數據庫再次啟動(dòng)??后,我們就可以不用密碼直接登錄數據庫修改密碼了。
# skip-grant-tables 模式下修改root密碼
[root@(′▽?zhuān)?)ho( ?▽?)st ~]# mysql
Welcome to the MySQL monitor. Comma(?_?;)nds 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. Al(′;ω;`)l rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates.?? Other names may be trade??marks 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 參數,然后重啟下數據庫即可。
2.幾種修改密碼的方法
除去忘記密碼,可能還(╬ ò﹏ó)有其他情(qing)景需要修改密碼,這時(shí)候就可以采取普通方式修改密碼了。還是以 MySQL 5.7 版本為例,介紹幾種常用的修改密碼的方法。
比如如果想更改 testuser 賬號的密碼,我們可以使用 root 賬號登錄,然后執行 alter user 命令更改?? testus??er 賬號的密碼。
mysql> alter user 'testuser'@'%' identified by 'Password1';
Query OK, 0 rows affect??ed (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'@'%' = PASS┐(′?`)┌WORD('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用戶(hù)名 -p舊密碼 passwor(′?_?`)d 新密碼
[root@host ~]# mysqladmin -utestuser -pPa??ssword2 password Password3
mysq(′_ゝ`)ladmin: [Warning] Us???ing 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)
Oracle is a reg??istered tradem??ark of Oracle Corpora??tion 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 表里面,我們也可以直接通過(guò) update user 表來(lái)修改密碼。(//ω//)
# 5.7及之后版本
mys(╯‵□′)╯ql> update mysql.user set authentication_string = password ('Password4') where user = 'testuser' and host = '%(◎_◎;)';
Query OK, 1 row affected, 1 warning (0.06 sec)
Row??s matched: 1 Changed: 1 Warnings: 1
mysql>(′;ω;`); flu(T_T)sh privileges;
Query OK, 0 rows affected (0.01 sec)
# 5.6及之前版本
update mysql.user se??t password=password('新密碼') where user='用戶(hù)名' and host='host';
3.設置 login-path 本地快捷登陸
為了防止密碼暴露及┐(′д`)┌忘記密碼,我們還可以設置 login??-path 來(lái)實(shí)現在本地不(′_ゝ`)輸密碼快捷登錄。
login-path 是 MySQL 5.6 開(kāi)始支持的新特性。通過(guò)借助 mysql_config_editor 工具將登陸 My(′?`)SQL 服務(wù)的認證信息加密保存在 .mylogin.cnf 文件(默認位于用戶(hù)主目錄)。MySQL 客戶(hù)端工具可通過(guò)讀取該加密文件連接 MySQL ,實(shí)現快捷登錄。
假??設我們想配置 root 賬號在本地快捷登錄,可以這么做:
# 執行回車(chē)后需要輸入一次rootヾ(?■_■)ノ密碼
[root@h(╯°□°)╯ost?? ~]# mysql_config_editor set --login-path=root -uroot -hlocalhost -p -P3306
En( ?° ?? ?°)ter pa(′?_?`)ssword:
# 配置完成后可以使用ヾ(?■_■)ノlogin-path登錄
[root@host ~]# mysql --login-path=root
Welcome to the Myヽ(′ー`)ノSQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2919
Server version: 5.7.23-log MySQL Community Server (GPL)
Oracle is a regi(′;ω;`)stered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of thei??r respective
owners.
Type 'help;' or '\h' for help. Type '\??c' to clear the current input state??ment.
mysql>
總結:
本篇文章主要介紹了修改數據庫賬號密碼的幾種方法,基本涵蓋了所有的場(chǎng)景。這里ヽ(′ー`)ノ也提醒下各位,數據庫賬號最好限制ip段登錄,密碼盡量復雜些,最好能夠定期修改,特別是重要的環(huán)境不能有半點(diǎn)馬虎。年底了??,安全才是王道。
到此這篇關(guān)于MySQL修改賬號密碼方法大全(小結)的文章就介紹到這了,更多相關(guān)MyS??QL修改賬號密碼內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
來(lái)源:腳本之家
鏈接:https://www.jb51.net/article/202411.htm


網(wǎng)站二維碼
導航
電話(huà)
短信
咨詢(xún)
地圖
分享