Summary of MySQL password restoration and modification methods

Source: Internet
Author: User

We know that the password is set for the MySQL database to improve the security of the MySQL database, but if we accidentally forgetMySQL passwordAt this time, we cannot log on to the MySQL database, which brings a lot of inconvenience to our use. Therefore, it is necessary to master the password restoration and modification methods of the MySQL database. This article mainly summarizes several methods for restoring and modifying the password of the MySQL database. Next, let's take a look at this part.

I. How to restore the MySQL password

If you forgetRootPassword. You can reset it in the following ways:

1. KILL the MySQL process in the system; killall-TERM mysqld

2. Run the following command to start MySQL without checking its permissions;

Safe_mysqld -- skip-grant-tables &

3. Use the empty password to log on to MySQL as the root user;

Mysql-u root

4. Modify the password of the root user;

 
 
  1. Mysql> update mysql. user set password = PASSWORD ('new password') where User = 'root ';
  2.  
  3. Mysql> flush privileges;
  4.  
  5. Mysql> quit

Restart MySQL to log on with the new password.

Ii. How to change the MySQL password

Method 1:

1. Edit the MySQL configuration file (the best combination with PHP:

In windows: % MySQL (the best combination with PHP) _ installdir % my. ini // I. ini is the configuration file of MySQL (the best combination with PHP.

In linux:/etc/my. cnf

Add the following line in the [MySQL (best combination with PHP) d] configuration section:

Skip-grant-tables

Save and exit editing.

2. Restart MySQL (the best combination of PHP and MySQL ).

In windows:

Net stop MySQL (the best combination with PHP)

Net start MySQL (the best combination with PHP)

In linux:

/Etc/init. d/MySQL (the best combination with PHP) d restart

3. Set a new ROOT password.

Then run the following command in the command line:

MySQL (the best combination with PHP)-uroot-p MySQL (the best combination with PHP)

Press enter without a password to go to the database tutorial.

Run the following statement to update the root password to 7758521:

Update user set password = PASSWORD ("7758521") where user = 'root ';

Quit exits MySQL (the best combination with PHP ).

4. Restore the configuration file and restart the service.

Then, modify the MySQL configuration file (the best combination with PHP) to delete the line added.

Restart MySQL (the best combination with PHP) again, and the password is changed.

Method 2:

 
 
  1. mysql> Insert INTO mysql.user (Host,User,Password)  
  2.  
  3. VALUES(’%’,’jeffrey’,PASSWORD(’biscuit’));  
  4.  
  5. mysql> FLUSH PRIVILEGES 

Specifically, this is adding a user with the username jeffrey and password biscuit. I wrote this example in mysql Chinese reference manual.

Be sure to use the PASSWORD function, and then use flush privileges.

Method 3:

Use mysqladmin, which is a special case stated above.

Mysqladmin-u root-p password mypasswd

After entering this command, you need to enter the original root password, and then the root password will be changed to mypasswd. Change the root in the command to your username, and you can change your password.

Of course, if your mysqladmin cannot connect to mysql server, or you cannot execute mysqladmin, this method is invalid, and mysqladmin cannot clear the password.

Here is a summary of how to restore and modify the MySQL password. If you want to know

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.