Resetting the root password for MySQL

Source: Internet
Author: User
Recently, MySQL installed on Mac is not used for a period of time. When I tried to use it, I found that I forgot my password. Fortunately, google soon found a solution. No relevant records at the time

Recently, MySQL installed on Mac is not used for a period of time. When I tried to use it, I found that I forgot my password. Fortunately, google soon found a solution. No relevant records at the time

Recently, MySQL installed on Mac is not used for a period of time. When I tried to use it, I found that I forgot my password. Fortunately, google soon found a solution. At that time, no relevant records were made. Today, we encountered the same problem on a MySQL server in the company. However, this solution was not as smooth as last time, so we made a record.

To reset the password of MySQL, follow these steps ¶
Add the following lines in the [mysqld] configuration section of my. cnf:

> Skip-grant-tables

You can also add-skip-grant-tables in the startup parameter background.

After restarting MySQL, run the following command to log on:

> Mysql-u root

In this way, you can enter MySQL, and then use the following statement to change the root password.

Mysql> use mysql;
Mysql> update user set password = PASSWORD ("NEW-ROOT-PASSWORD") where User = 'root ';
Mysql> flush privileges;
Mysql> quit

Normally, the above steps are OK. However, if MySQL is not started with port 3306, the above method will not work. You must change the port to 3306 and then follow the above method. Finally, you should also note that you should remove the skip-grant-tables option after the modification is complete, so as not to let the MySQL Server Always run without the Password Logon method.

Related reading:

Solution for Windows/Linux MySQL to forget the root password

How to solve the problem of forgetting the root password of MySQL

Change the root password for MySQL

How to reset the root password of the MySQL server in Ubuntu

Restore the MySQL root Password under Red Hat

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.