Restore the MySQL root Password under Red Hat

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.