MySQL forgot root user password under Linux

Source: Internet
Author: User
Tags mysql login

Today, when receiving a MySQL server, I found that I forgot the password of the root user of MySQL, looked for the data and sent the various documents without the root user password, so we need to change the root user password.
First verify that the server is in a secure state, that is, no one can connect to the MySQL database arbitrarily. Because the MySQL database is completely out of password-protected state during the reset of the root password of MySQL, other users can log in and modify the MySQL information arbitrarily.The safest state is to operate on the console of the server and unplug the network cable.

1. Modify MySQL Login settings:
The skip-grant-tables added to the paragraph in [mysqld]
# sed-i '/\[mysqld\]/a\skip-grant-tables '/etc/my.cnf

2. Restart Mysqld
# service Mysqld Restart
Shutting down MySQL. success!
Starting MySQL. success!

3. Log in and modify the root password of MySQL
#/usr/bin/mysql
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 1
Server version:5.6.19 Source Distribution

Copyright (c), the Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of the Oracle Corporation and/or its
Affiliates. Other names trademarks of their respective
Owners.

mysql> use MySQL;
Reading table information for completion of table and column names
Can turn off this feature to get a quicker startup with-a
Database changed

mysql> UPDATE user SET Password = Password (' doiido ') WHERE user = ' root ';
Query OK, 3 rows affected (0.01 sec)
Rows Matched:3 Changed:3 warnings:0

mysql> flush Privileges;
Query OK, 0 rows affected (0.01 sec)

Mysql> quit
Bye

4. Change the MySQL login settings back
Delete the skip-grant-tables you just added in the paragraph [mysqld]
# sed-i "/skip-grant-tables/d"/etc/my.cnf

5. Restart Mysqld
# service Mysqld Restart
Shutting down MySQL. success!
Starting MySQL. success!

At this point, you can use Root/doiido to log in.


MySQL forgot root user password under Linux

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.