In this case, the root password of MySQL is lost. To restore it, let's talk about the environment first:
Red Hat Enterprise Linux 6.3 x86_64
MySQL 5.5.28
According to your previous experience, modify my. cnf: Add skip-grant-tables in [mysqld], restart MySQL, and try mysql password-free login. Then you can change the password, however, it seems that this trick is not very clever. There is another feasible and simple way!
1. Stop MySQL normally first
Service mysql stop
2. Create the file test. init.
UPDATE mysql. user SET Password = PASSWORD ('') WHERE User = 'root ';
Flush privileges;
3. Start
Mysqld_safe -- init-file = test. init &
In this way, you can use mysql to log on to MySQL without a password. In fact, the PASSWORD has been reset in test. init, but it is empty. You can fill in your PASSWORD in the 2nd PASSWORD brackets.
4. normal startup
After step 1 is executed, If you execute service mysql restart again, you will find that MySQL cannot start up with an error, but 3rd is still in the listening status, because mysql_safe has been used for special startup in step 2, we want to kill this process:
Ps aux | grep mysql
Kill-9 PID
Find the MySQL process, Kill it, and execute the service command to start it normally.