First step: (Stop running MySQL)
[Root@maomao ~]# service mysqld Stop
Stopping MySQL: [ OK ]
Step two: Restart MySQL with the "--skip-grant-tables" parameter
[Email protected] ~]# Mysqld_safe--skip-grant-tables
[email protected] ~]# starting mysqld daemon with databases From/var/lib/mysql
Note: If you stop at this point, please open the SSH login and proceed to the next step.
Step three: Log in to MySQL with your account
[Email protected] ~]# mysql-u root
Welcome to the MySQL Monitor. Commands End with; or \g.
Your MySQL Connection ID is 1
Server version:5.0.77 Source Distribution
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the buffer.
Fourth step: Change the user database
mysql> use MySQL
Reading table information for completion of table and column names
Can turn off this feature to get a quicker startup with-a
Database changed
Fifth Step: Change the password, below () The root123 is Xinmi Code
mysql> Update user Set Password=password (' root123 ') where user= ' root ';
Query OK, 3 Rows Affected (0.00 sec)
Rows Matched:3 Changed:3 warnings:0
Sixth step: Refresh the Permissions table
mysql> Flush Previleges;
Error 1064 (42000): You have a error in your SQL syntax; Check the manual-corresponds to your MySQL server version for the right syntax-use-near ' previleges ' on line 1
Seventh Step: Exit MySQL
Mysql> quit
Bye
Eighth Step: Restart MySQL
[[Email protected] ~]# service mysqld restart;
Stopping MySQL: [ OK ]
Starting MySQL: [ OK ]
Nineth Step: Re-login with a changed password.
[Email protected] ~]# mysql-u root-p
Enter password:admin123
Welcome to the MySQL Monitor. Commands End with; or \g.
Your MySQL Connection ID is 2
Server version:5.0.77 Source Distribution
Type ' help ', ' or ' \h ' for help. Type ' \c ' to clear the buffer.
Mysql> quit
Bye
[Email protected] ~]#
Add the following auto-start command/etc/rc.d/init.d/mysqld start
CentOS system MySQL forgot root user's password