Solution for forgetting the MySQL Root Password in Linux

Source: Internet
Author: User

Recently, the root password of MySQL in the lab has been changed. You need to find a way to change the new password. The method is as follows:

1. Disable the MySQL service.

/Etc/init. d/mysqld stop

2. Use the-Skip-grant-tables option to start the MySQL service. You can add this option to the startup location of the/etc/inin. d/mysqld script,

VI/etc/init. d/mysqld

Add -- skip-grant-tables in the following statement to run the startup command.

/Usr/bin/mysqld_safe -- skip-grant-tables -- datadir = "$ datadir" -- socket = "$ socketfile "/
-- Log-error = "$ errlogfile" -- PID-file = "$ mypidfile "/

Adding -- skip-grant-tables means that the permission table authentication is skipped when the MySQL service is started. After MySQL is started, the root user connected to MySQL does not need a password.

3. Restart the MySQL service.

/Etc/init. d/mysqld start

4. Modify the password of the root user;

Mysql> Update mysql. User SET Password = PASSWORD ('000000') where user = root;
Mysql> flush privileges;
Mysql> quit

5. Restart MySQL to log on with the new password.

Mysql-u root-P
Enter Password 123456

6. Disable the MySQL service.

/Etc/init. d/mysqld stop
7. Modify the/etc/init. d/mysqld modified in step 1 to keep it unchanged. That is, cancel the -- skip-grant-tables statement.
8. Restart the MySQL service.
 /etc/init.d/mysqld start

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.