How to solve the problem after MySQL forgets the password (NT/Linux)

Source: Internet
Author: User

[Windows]

1. Stop MySQL service: Open the command line window CMD and net stop MySQL
2. Start MySql in another way: Use mysqld-nt.exe to start MySql in the directory of the installation directory of mysqlin the command line:

Mysqld-NT -- skip-grant-tablesNote: The cmd window cannot be closed.
3. Enter MYSQL: In addition, open a command line window and execute MySql in the bin directory. You do not need to enter a password.
> Use MySQL
> Update user SET Password = PASSWORD ("new_pass") where user = "root ";
> Flush privileges;
> Exit

Note:

1) if you are familiar with SQL statements, update does not need to explain that the first user is the table name and the second user is the field in the table. The first password is the table field, and the second password () is the encryption function. New_pass is the password to be changed.
2) flush privileges does not need to be added. However, you must note that the Host field cannot be localhost. Because after using this method, you cannot connect with localhost. You can change this field to an IP address or a wildcard character.
> Update user set host = "192.168.0.1" where user = "root"
4. Use the task manager to locate the mysqld-nt process and end the process!
5. Restart the MySQL service and use the new password to log on to net start MySQL.

 

[Linux]

 

1. Close MYSQL: If MySQL is running, killall-term mysqld will be killed first.
2. Use another method to start MYSQL: Bin/safe_mysqld -- skip-grant-tables &
3. You can enter MySQL without a password.

> Use MySQL
> Update user SET Password = PASSWORD ("new_pass") where user = "root ";
> Flush privileges;

Note: Same as above
4. Kill MySQL again and start MySql in a normal way.

 

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.