Forgot your password mysql three ways how to reset your password, and change the root password

1. First stop MySQL,

Command: systemctl stop mysqld # stopped MySQL

Command: systemctl status mysqld # View state

 

 2. Authorization Form and then skip start MySQL service program

This step is mainly using the mysqld --skip-grant-tables option

My.cnf configuration modifications, additions skip_grant_tables = 1 Start setting:

Open the configuration file /etc/my.cnf

Add skip_grant_tables a row, then save and exit

 

 3. Then start MySQL and view status

Command: systemctl start mysqld 

 

4. Using MySQL mysql command to connect to the service, to reset the root password

Since the start of the previous step to skip the authorization table MySQL service, so you can log in directly from the machine root

In the mysql command-line input directly to

 

 

 

 5. After entering mysql> environment, by modifying the relevant record in the user table of the mysql reset root user login password from the machine:

命令:update mysql.user set authentication_string=password('123qqq...A')   where user='root' and host='localhost';

                                 # Reset the password

Command: FLUSH PRIVILEGES; # refresh the authorization list

Then enter exit to exit mysql

Note: By executing "FLUSH PRIVILEGES;" authorization form allows immediate effect, for the normal operation of MySQL service, you can also use the above method to modify the password, do not restart the service. Since the present embodiment is the recovery password, preferably restart the MySQL service program, so the above-described "FLUSH PRIVILEGES;" operation may be skipped.

 

 6. Restart the MySQL service program in the normal way to verify a new password

   If the previous configuration is to modify the method to skip /etc/my.cnf authorization table, the root password after a reset, the appropriate settings should be removed to restore normal:

 

 

 

 7. The new password reset in order to successfully log in (try the freshly baked bar code):

 

 OK! Now forget how to password reset is done, the next step is to modify root password in three ways:

 

1. Reset the administrator password root

Normal premise is: Given the current MySQL user management (root) password.

Method: Shell is provided at the command line

Use mysqladmin management tools need to verify old password. For example, the following will set the root password for the A ... qqq321:

   Command: mysqladmin -uroot- -p password 'A ... qqq321'

 

 

 

 

2. Change the administrator's root password to other methods (three kinds)

After 1) Method 1, to sign mysql root>, using the instruction set password provided

This is the same with the new requirements when installing MySQL-server for the first time to change the password the way, can also be used in peacetime

Extended what (if there is

ERROR 3009 (HY000): Column count of mysql.user is wrong Expected 45, found 42. Created with MySQL 50564, now running 50726. Please use mysql_upgrade to fix this error this error, because not update the database structure. information leading to the input line of command to solve: mysql_upgrade -uroot -p'123qqq ... a ') 

Because I was being given too much change your password, it could lead to, use the table did not update the user password again before this

 

 Well, that sort of situation may appear, just continue to change passwords

命令:set password for root@localhost=password('1234567');     

 

 To test

 

 

After 2) Method 2, to sign mysql root>, using the authoring tool is provided GRANT

This is the most common users License:

命令: grant all ON *.* TO root@localhost identified by '123qqq...A';

 

 

3) Method 3, to sign mysql root>, using UPDATE update records corresponding table

This method is the same as operation recovery password:

 

 

 

 In the above method, it requires special attention: When MySQL service program starts to skip-grant-tables option, if you do not execute "FLUSH PRIVILEGES;" to set the password of operation, is not by way of grant or set password. MySQL login or verify this in two ways, will see the error ERROR 1045:

 

 

 

to sum up:. . . . . . . . . . (Slightly provinces and one million words here)

 

Guess you like

Origin www.cnblogs.com/zgqbky/p/11720406.html