mysql忘記root用戶密碼了?來(lái)看看怎么找回吧

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

修改或找回root密碼步驟
1.修改MySQL的登錄設(shè)置:

    # vi /etc/my.cnf 

在[mysqld]的段中加上一句:skip-grant-tables 保存并且退出vi。
2.重新啟動(dòng)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' ; 
image

運(yùn)行報(bào)錯(cuò)

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


image

4.刷新權(quán)限

    mysql> flush privileges ; 
    mysql> quit;

5.將MySQL的登錄設(shè)置修改回來(lái)

    # vi /etc/my.cnf 

將剛才在[mysqld]的段中加上的skip-grant-tables刪除
保存并且退出vi。
6.重新啟動(dòng)mysqld

    # /etc/init.d/mysqld restart   ( service mysqld restart )

重新登錄成功 ,root用戶設(shè)置ok。

MySQL密碼的恢復(fù)方法二
有可能你的系統(tǒng)沒(méi)有 safe_mysqld 程序(比如我現(xiàn)在用的 ubuntu操作系統(tǒng), apt-get安裝的mysql) , 下面方法可以恢復(fù)

  1. 停止mysqld;
/etc/init.d/mysql stop

(您可能有其它的方法,總之停止mysqld的運(yùn)行就可以了)

  1. 用以下命令啟動(dòng)MySQL,以不檢查權(quán)限的方式啟動(dòng);
mysqld --skip-grant-tables &
  1. 然后用空密碼方式使用root用戶登錄 MySQL;
mysql -u root
  1. 修改root用戶的密碼;
mysql> update mysql.user set password=PASSWORD('newpassword') where User='root'; 
mysql> flush privileges; 
mysql> quit 

重新啟動(dòng)MySQL

    /etc/init.d/mysql restart

就可以使用新密碼 newpassword 登錄了。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容