Mysql Root password forgotten solution in Linux environment (three kinds) _mysql

Source: Internet
Author: User
Tags flush mysql login password protection

One of the ways to restore MySQL passwords

1. First, verify that the server is in a secure state, that is, no one can arbitrarily connect to the MySQL database. Because the MySQL database is completely out of password protection during the reset of the MySQL root password, other users can also arbitrarily log in and modify MySQL information. The server's quasi-security status can be achieved by blocking 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 MySQL login settings:

 
 

In the paragraph of [mysqld], add a sentence: Skip-grant-tables Save and Exit VI.

3. Reboot mysqld

#/etc/init.d/mysqld Restart (Service mysqld restart)

4. Log in and modify the MySQL root password

mysql> use MySQL; 
mysql> UPDATE user SET Password = Password (' New-password ') WHERE user = ' root '; 
mysql> flush Privileges; 
Mysql> quit

5. Change the MySQL login settings back

 
 

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

Save and Exit VI.

6. Reboot mysqld

#/etc/init.d/mysqld Restart  (Service mysqld restart)

7. Restore the server's normal working status

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

MySQL password recovery method bis

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

1. Kill off the MySQL process in the system;

Killall-term mysqld

2. Use the following command to start MySQL, to do not check the permissions of the way to start;

Safe_mysqld--skip-grant-tables &

3. Then use the null password method to log in to MySQL with root user;

Mysql-u Root

4. Change the password of root user;

mysql> Update Mysql.user Set Password=password (' New password ') where user= ' root '; 
mysql> flush Privileges; 

Restart MySQL and you can log on with the new password

MySQL Password recovery method three

It is possible that your system does not have SAFE_MYSQLD programs (such as I now use the Ubuntu operating system, Apt-get installed MySQL), the following methods can be restored

1. Stop mysqld;

/etc/init.d/mysql stop

(You may have other methods, in short stop the mysqld run on it)

2. Use the following command to start MySQL, to do not check the permissions of the way to start;

Mysqld--skip-grant-tables &

3. Then use the null password method to log in to MySQL with root user;

Mysql-u Root

4. Change the password of root user;

mysql> Update Mysql.user Set Password=password (' NewPassword ') where user= ' root '; 
mysql> flush Privileges; 

Restart MySQL

/etc/init.d/mysql restart

You can log on using the new password NewPassword.

The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.