mysql忘記root用戶密碼找回步驟


修改或找回root密碼步驟
1.修改MySQL的登錄設置: # vi /etc/my.cnf 在[mysqld]的段中加上一句:skip-grant-tables 保存並且退出vi。 2.重新啟動mysqld # /etc/init.d/mysqld restart ( service mysqld restart )
3 mysql -uroot -p 回車
mysql> USE mysql ; 
mysql> UPDATE user SET Password = password ( 'new-password' ) WHERE User = 'root' ; 

運行報錯

改為 update mysql.user set authentication_string=password('123456a') where user='root';

4.刷新權限 

mysql> flush privileges ; 
mysql> quit;
5.將MySQL的登錄設置修改回來 
# vi /etc/my.cnf 
將剛才在[mysqld]的段中加上的skip-grant-tables刪除 
保存並且退出vi。
6.重新啟動mysqld 
# /etc/init.d/mysqld restart   ( service mysqld restart )
重新登錄成功 ,root用戶設置ok。

 

MySQL密碼的恢復方法二
有可能你的系統沒有 safe_mysqld 程序(比如我現在用的 ubuntu操作系統, apt-get安裝的mysql) , 下面方法可以恢復
1. 停止mysqld; 
/etc/init.d/mysql stop
(您可能有其它的方法,總之停止mysqld的運行就可以了)
2. 用以下命令啟動MySQL,以不檢查權限的方式啟動; 
mysqld --skip-grant-tables &
3. 然后用空密碼方式使用root用戶登錄 MySQL; 
mysql -u root
4. 修改root用戶的密碼; 
mysql> update mysql.user set password=PASSWORD('newpassword') where User='root'; 
mysql> flush privileges; 
mysql> quit 
重新啟動MySQL
/etc/init.d/mysql restart
就可以使用新密碼 newpassword 登錄了。



 
       


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM