CentOS6.8下MySQL數據庫忘記root密碼解決方法


一、更改my.cnf配置文件

編輯/etc/my.cnf文件,在[mysqld]下添加skip-grant-tables,保存退出。如圖:

重啟mysql服務:services mysqld restart

二、更改root密碼

重啟mysqld服務后,執行mysql命令,進入mysql命令行:

[root@yeebian ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, 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> 

修改root密碼

mysql> UPDATE mysql.user SET Password=PASSWORD('mysqladmin') where USER='root';
Query OK, 0 rows affected (0.00 sec)
Rows matched: 3  Changed: 0  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> exit
Bye

三、刪除/etc/my.cnf中的skip-grant-tables,或者注釋掉,重啟mysql即可。

 


免責聲明!

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



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