What should I do if I forget the MySQL root Password?

Source: Internet
Author: User

What should I do if I forget the MySQL root Password?

In the daily development or maintenance of MySQL, it is often difficult to avoid some problems or faults, such as lost passwords and table damage. To sum up the commonForget the MySQL root PasswordSolution:

1. log on to the server where the database is located and manually kill the Mysql process

Command:Kill process number(In linux)
Command:Taskkill process number(Win)
How can I view the process number?
We all know that the MySQL process number is generally stored in the Mysql data directory, which records the Mysql service process number. The file name is hostname. pid, as shown below, where YEGZT8JOIIU2LKY is the host name.

 

Run the ps command to view processes in linux. In win, run tasklist to view process numbers,

Open the file and you can see that it only records the process number.

 

Now, for convenience, I mainly demonstrate how to operate in windows. I am not ready to open the Virtual Machine for testing. If we are not familiar with the taskkill command, we can use taskkill /? To view the command.

 

2. Use the-skip-grant-tables option to restart the MySQL service.

Linux
Syntax:./bin/mysqld_safe-skip-grant-tables
The-skip-grant-tables option indicates that mysql is started.
(Note that for Mysql installed in win, I use mysqld-skip-grant-tables)

3. Use the root user with an empty password to connect to MySQL and modify the root password.

 

Modify as follows:

The set password command fails because-skip-grant-tables is used for startup.

 

Use the update statement to directly update the user table in the mysql database.

4. Update Permissions

5. Log On again

After logging out, you can only use the password to log on to mysql-uroot.

The above is the solution for forgetting the root password, hoping to help you learn.

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.