小編給大家分享一下解決MySQL忘了root密碼的方法,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!
成都創(chuàng)新互聯(lián)公司主要從事成都做網(wǎng)站、網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務(wù)。立足成都服務(wù)石柱土家族,10多年網(wǎng)站建設(shè)經(jīng)驗(yàn),價(jià)格優(yōu)惠、服務(wù)專(zhuān)業(yè),歡迎來(lái)電咨詢(xún)建站服務(wù):18982081108
mysql忘了root密碼解決方法:
1、修改配置文件my.cnf,在配置文件[mysqld]下添加skip-grant-tables,重啟MySQL服務(wù)即可免密碼登錄
# SERVER SECTION # ---------------------------------------------------------------------- # # The following options will be read by the MySQL Server. Make sure that # you have installed the server correctly (see above) so it reads this # file. # [mysqld] skip-grant-tables
2、用空密碼的 root 用戶(hù)連接到 MySQL,并且更改 root 口令:
[root@localhost mysql]# mysql -uroot Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 53 Server version: 5.0.41-community-log MySQL Community Edition (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123'; ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement mysql> update user set authentication_string = NULL where user = 'root'; Query OK, 1 row affected (0.00 sec)
上面是先用grant的方式修改root密碼,但是由于使用了配置了skip-grant-tables 選項(xiàng),使用“alter user”命令更改密碼失敗,直
接更新 user 表的 authentication_string字段后更改密碼成功。
3、到my.cnf 中刪除skip-grant-tables選項(xiàng),然后直接用mysql -uroot免密碼登錄后,在執(zhí)行如下語(yǔ)句重設(shè)密碼
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123';
看完了這篇文章,相信你對(duì)解決mysql忘了root密碼的方法有了一定的了解,想了解更多相關(guān)知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!