溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

mysql忘了root密碼的解決方法

發布時間:2020-07-16 11:02:56 來源:億速云 閱讀:210 作者:清晨 欄目:編程語言

這篇文章將為大家詳細講解有關mysql忘了root密碼的解決方法,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

修改配置文件my.cnf,在配置文件[mysqld]下添加skip-grant-tables,重啟MySQL服務即可免密碼登錄

其中--skip-grant-tables 選項前面曾經介紹過,意思是啟動 MySQL 服務的時候跳過權限表認證。 啟動后,連接到 MySQL 的 root 將不需要口令。

# 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

用空密碼的 root 用戶連接到 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 選項,使用“alter user”命令更改密碼失敗,直

接更新 user 表的 authentication_string字段后更改密碼成功。

到my.cnf 中刪除skip-grant-tables選項,然后直接用mysql -uroot免密碼登錄后,在執行如下語句重設密碼:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123';

關于mysql忘了root密碼的解決方法就分享到這里了,希望以上內容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女