Several password recovery methods used in MySQL

Source: Internet
Author: User
Tags flush

Several password recovery methods commonly used in MySQL tutorials
/*
One of the methods of restoring MySQL password
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;
Mysql> quit


Restart MySQL and you can log on with the new password

Ii. Methods of Modification

1, edit the MySQL (and PHP collocation of the best combination) Profile:

Windows environment:%mysql (the best combination of PHP) _installdir%my.ini//General configuration file with My.ini, MySQL (the best combination of PHP) and MySQL (best combination of PHP).
Linux Environment:/ETC/MY.CNF

Add the following line to the [MySQL (best combination with PHP) d] configuration section:
Skip-grant-tables

Save exit Edit.

2, and then restart MySQL (and PHP with the best combination) services

In the Windows environment:
net stop MySQL (best combination with PHP)
net start MySQL (best combination with PHP)

In Linux environments:
/etc/init.d/mysql (best combination with PHP) d restart

3, set the new root password

And then execute at the command line:
MySQL (best combination with PHP)-uroot-p MySQL (best combination with PHP)
Direct return without a password to enter the database tutorial.

Now we execute the following statement to update the root password to 7758521:
Update user set Password=password ("7758521") where user= ' root ';

Quit Exit MySQL (the best combination with PHP).

4, restore the configuration file and restart the service

Then modify the MySQL (and PHP Best Mix) profile to remove the line that you just added.

Re-reset MySQL (and PHP with the best combination) service, password modification completed.


Method Three

Mysql> Insert into Mysql.user (Host,user,password)

VALUES ('% ', ' Jeffrey ', PASSWORD (' biscuit '));

Mysql> FLUSH Privileges

To be exact, this is adding a user, the username is Jeffrey, and the password is biscuit. There is this example in the MySQL Chinese reference manual, so I wrote it.

Note that you want to use the password function, and then use flush privileges.


Method Four

Using Mysqladmin, this is a special case of the previous declaration.

mysqladmin-u root-p Password mypasswd


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

Of course, if your mysqladmin is not connected to MySQL server, or you have no way to execute mysqladmin, then this method is invalid, and mysqladmin cannot empty the password.

The following methods are used at the MySQL prompt and must have the root permissions of MySQL:

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.