linux下,mysql忘記root密碼解決方法--mysql修改root密碼
linux管理員可能出現忘記mysql root密碼的狀況,能夠進行以下的步驟從新設置MySQL的root密碼:
1.首先確認服務器出於安全的狀態,也就是沒有人可以任意地鏈接MySQL數據庫。
由於在從新設置MySQL的root密碼的期間,MySQL數據庫徹底出於沒有密碼保護的
狀態下,其餘的用戶也能夠任意地登陸和修改MySQL的信息。能夠採用將MySQL對
外的端口封閉,而且中止Apache以及全部的用戶進程的方法實現服務器的準安全
狀態。最安全的狀態是到服務器的Console上面操做,而且拔掉網線。
2.修改MySQL的登陸設置:
# vi /etc/my.cnf
在[mysqld]的段中加上一句:skip-grant-tables
例如:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
保存而且退出vi。
3.從新啓動mysqld
# /etc/init.d/mysqld restart
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
4.登陸並修改MySQL的root密碼
# /usr/bin/mysql
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 3 to server version: 3.23.56
Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> USE mysql ;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed mysql> UPDATE user SET Password = password ( 'new-password' ) WHERE User = 'root' ; Query OK, 0 rows affected (0.00 sec) Rows matched: 2 Changed: 0 Warnings: 0 mysql> flush privileges ; Query OK, 0 rows affected (0.01 sec) mysql> quit Bye 5.將MySQL的登陸設置修改回來 # vi /etc/my.cnf 將剛纔在[mysqld]的段中加上的skip-grant-tables刪除 保存而且退出vi。 6.從新啓動mysqld # /etc/init.d/mysqld restart Stopping MySQL: [ OK ] Starting MySQL: [ OK ] 7.恢復服務器的正常工做狀態 將步驟一中的操做逆向操做。恢復服務器的工做狀態。
歡迎關注本站公眾號,獲取更多信息