溫馨提示×

溫馨提示×

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

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

Mysql 5.7中忘記root密碼怎么辦

發(fā)布時間:2021-07-24 17:34:04 來源:億速云 閱讀:193 作者:Leah 欄目:MySQL數據庫

這篇文章給大家介紹Mysql 5.7中忘記root密碼怎么辦,內容非常詳細,感興趣的小伙伴們可以參考借鑒,希望對大家能有所幫助。

修改mysql參數文件:
[root@test ~]# vi /etc/my.cnf

[mysqld]后面加入:
skip-external-locking

保存。

[root@test ~]# service mysqld restart
MySQL server PID file could not be found!                  [FAILED]

不需要密碼就能登錄:
[root@test ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.19-log MySQL Community Server (GPL)


Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


MySQL [(none)]> USE mysql ;
Database changed

MySQL [mysql]> update user set authentication_string=password('test') where user='root' and Host = '127.0.0.1'; 
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 1  Changed: 1  Warnings: 1


MySQL [mysql]> update user set authentication_string=password('test') where user='root' and Host = '%'; 
Query OK, 0 rows affected, 1 warning (0.00 sec)
Rows matched: 0  Changed: 0  Warnings: 1

修改完畢。
再把原來在/etc/my.cnf里面[mysqld]后面的
skip-external-locking
去掉。

需要輸入密碼登錄:
[root@test ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.19-log MySQL Community Server (GPL)


Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


MySQL [(none)]> 

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

向AI問一下細節(jié)

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

AI