MySQLroot user forgot password solution (security mode, password modification methods)

Source: Internet
Author: User

MySQLroot user forgot password solution (security mode, password modification methods)

1. Disable running MySQL
2. Run the following command to start the Security Mode of MySQL:

mysqld --skip-grant-tables

Or

mysqld-nd --skip-grant-tables
3. log on to MySQL using the root user [password-free]
mysql -u root -p

Enter the password and press Enter.
4. Select the MySQL System Library
use mysql


5. view the root password of the current system user
select user,host,password from user where user="root"

The password is encrypted. If you want to restore the current password, run this command to back up the current password.
6. Modify the password of the root user
update user set password=PASSWORD("your_password") where user="root"

Here, the password of the root user is directly modified in all login locations. If you only want to modify the password of the root user in a certain place, you can add a condition host = 'somewhere' in the previous command'
For example, the following command modifies the login password of the root user on the local localhost.
update user set password=PASSWORD("your_password") where user="root" and host="localhost"

The above operation is to directly modify the MySQL System database mysql, which is less secure. In case of misoperation, the cost is high and it is difficult to recover, and it is limited to users who have the UPDATE permission on the mysql database, mySQL itself provides us with a simpler operation method. Here is a brief introduction.
Modify the password of the current login user and use SELECT CURRENT_USER (); to view the current Login User
SET PASSWORD = PASSWORD('cleartext password');

Modify the logon password of bob at % .example.org. Note that the host address % .example.org must exist.

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

Of course, we can also change the password through GRANT.
GRANT USAGE ON *.* TO 'bob'@'%.example.org' IDENTIFIED BY 'cleartext password';

For more information about password modification, see the official document (5.6)
Http://dev.mysql.com/doc/refman/5.6/en/set-password.html
7. Refresh the system permissions.
flush privileges;

8. disable the security mode of MySQL and restart it.

Note:

In step 1, when the security mode is enabled, the command line may remain suspended. At this time, Ctrl + c cannot terminate the operation, at this time, you only need to check whether the MySQL port is in the listening State through netstat-ao. If yes, it means that MySQL has entered the safe mode. This is mainly because MySQL does not advocate the safe mode for a long time to run.

When you use the mysql command to connect to the database, the following error may occur:
ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)
There are many descriptions about this error on the Internet. We know that the default port of MySQL is 3306. when the service is started on another port, the corresponding port is not specified when the mysql command is used, of course, the Server cannot be connected.

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.