MySQL root user Forgot password solution (Safe mode, three ways to change password)

Source: Internet
Author: User

1. Close the running MySQL
2. Start the MySQL security mode with the following command:

Mysqld--skip-grant-tables

Or

Mysqld-nd--skip-grant-tables


3. Log in to MySQL using the root user [password-free]
Mysql-u root-p

When entering a password, enter directly
4. Select the MySQL system library
Use MySQL


5. View the password for the current system user root
Select User,host,password from user where user= "root"

Check the password is encrypted, if you want to restore the current password in the future can run this command to back up the current password
6. Modify the root user's password
Update user set Password=password ("Your_password") where user= "root"

Here is a direct modification of the root user in all login location password, if you just want to change the root in a place password, you can add a qualification in the previous command host= ' somewhere '
For example, the following command modifies the root user's login password on native localhost
Update user set Password=password ("Your_password") where user= "root" and host= "localhost"

The above operation is directly to the MySQL system library MySQL modification, the security is low, once the error operation, high cost, difficult to recover, and limited to the MySQL library has update permissions for users, MySQL itself provides us with a more convenient way to operate, here for a brief introduction
Modify the password of the current login user, use Select Current_User (), to view the current login user
SET PASSWORD = PASSWORD (' cleartext PASSWORD ');


Change the login password of Bob user in%.example.org location, note that the host address here%.example.org must exist.

SET PASSWORD for ' bob ' @ '%.example.org ' = PASSWORD (' cleartext PASSWORD ');

Of course, we can also change the password by grant.
GRANT USAGE on * * to ' bob ' @ '%.example.org ' identified by ' cleartext password ';

For more information on changing your password please see the official documentation (5.6)
Http://dev.mysql.com/doc/refman/5.6/en/set-password.html
7. Refresh the system's permissions
Flush privileges;

8. Turn off MySQL's safe mode and reboot

Note:

in the 2nd step, when you start the security mode, the command line may be in the suspended state, at this time, CTRL + C can not terminate the operation, as long as the MySQL port through the Netstat-ao to see if the listening state, that is, the MySQL has entered the security mode, This behavior occurs primarily because MySQL does not advocate safe mode for a long time running

The following error may occur when you use the MySQL command to connect to a database:
ERROR 2003 (HY000): Can ' t connect to MySQL server on ' localhost ' (10061)
There are many descriptions of this error on the Web, we know that the default port for MySQL is 3306, and when you start the service on a different port, the MySQL command does not specify the corresponding port, and of course you cannot connect to the server.

Additional information:
MySQL Official document (5.5) http://dev.mysql.com/doc/refman/5.5/en/index.html
MySQL Official document (5.6) http://dev.mysql.com/doc/refman/5.6/en/index.html
etc...

MySQL root user Forgot password solution (Safe mode, three ways to change password)

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.