MySQL root password forgotten solution in Linux environment (three kinds)-recommend the third Kind

Source: Internet
Author: User
Tags flush mysql login

One of the ways to recover MySQL passwords

1. 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. It is possible to implement the server's quasi-security state by enclosing MySQL's external ports and stopping Apache and all user processes. The safest state is to operate on the console of the server and unplug the network cable.

2. To modify the login settings for MySQL:

?
1 # vi /etc/my.cnf

Add one sentence to the paragraph in [mysqld]: Skip-grant-tables Save and Exit VI.

3. Restart Mysqld

?
1 # /etc/init.d/mysqld restart ( service mysqld restart )

4. Log in and modify the root password of MySQL

?
1234 mysql> USE mysql ; mysql> UPDATEuser SET Password = password ( ‘new-password‘ ) WHERE User = ‘root‘ ; mysql> flush privileges; mysql> quit

5. Change MySQL login settings back

?
1 # vi /etc/my.cnf

Delete the skip-grant-tables you just added in the paragraph [mysqld]

Save and Exit VI.

6. Restart Mysqld

?
1 # /etc/init.d/mysqld restart  ( service mysqld restart )

7. Restore the server's normal working state

Reverse the action in step one. Restores the server's working status.

MySQL password recovery method of the second

If you forget the root password for MySQL, you can reset it in the following ways:

1. Kill the MySQL process in the system;

?
1 killall -TERM mysqld

2. Start MySQL with the following command to start without checking permissions;

?
1 safe_mysqld --skip-grant-tables &

3. Then log in to MySQL using the root user with a blank password;

?
1 mysql -u root

4. Change the password of the root user;

?
123 mysql> updatemysql.user set password=PASSWORD(‘新密码‘) whereUser=‘root‘; mysql> flush privileges; mysql> quit

Restart MySQL and you can log in with the new password

MySQL Password recovery method III (recommended)

It is possible that your system does not have a SAFE_MYSQLD program (such as the Ubuntu OS I am using now, Apt-get installed MySQL), the following method can be restored

1. Stop mysqld;

?
1 /etc/init.d/mysqlstop

(You may have other ways to stop mysqld running anyway)

2. Start MySQL with the following command to start without checking permissions;

?
1 mysqld --skip-grant-tables &

3. Then log in to MySQL using the root user with a blank password;

?
1 mysql -u root

4. Change the password of the root user;

?
123 mysql> updatemysql.user set password=PASSWORD(‘newpassword‘) whereUser=‘root‘; mysql> flush privileges; mysql> quit

Restart MySQL

?
1 /etc/init.d/mysqlrestart

You can log in with the new password newpassword.

MySQL root password forgotten solution in Linux environment (three kinds)-recommend the third Kind

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.