First, the general forgotten password solution, need to restart MySQL
1, Skip-grant-tables
Our common approach is to use the Skip-grant-tables option, and MYSQLD server does not use the rights system after startup (privilege system). Users do not need any accounts, unrestricted access to all data in the database. For security purposes, it is usually added skip-networking, mysqld does not listen for any TCP/IP connection requests. The operation process is as follows,
1) Modify the MY.CNF configuration file and add Skip-grant-tables and skip-networking to the MYSQLD option.
2 Restart Mysqld server.
3 Modify the Mysql.user table to store the password through the SQL statement. Perform flush privileges and re-enable the MySQL permissions system.
Copy Code code as follows:
UPDATE MySQL. USER SET Password=password (' newpwd ') WHERE user= ' root ';
FLUSH privileges;
4 Delete or annotate the parameter options for Skip-grant-tables and skip-networking in the configuration file. If you use skip-networking, you need to restart the mysqld again. Because skip-networking is not a system variable, it is only a mysqld parameter option and cannot be set dynamically through system variables. If skip-networking is not applied, only the flush privileges can be executed to bring the permission system back into effect.
2.--init-file
Mysqld_safe can enable the –init-file parameter option to execute a password-reset SQL statement.
1 Create a new initialization file, such as/tmp/initfile, where the file content is the SQL statement that modifies the password above.
Copy Code code as follows:
UPDATE mysql.user SET password=password (' newpwd ') WHERE user= ' root ';
FLUSH privileges;
2) Close the MYSQLD service process.
3) Use Mysqld_safe to start mysqld;
Copy Code code as follows:
Mysqld_safe--init-file=/home/me/mysql-init &
The above two methods are to reset the password in the case of forgetting the root password, you can find that all need to restart the MYSQLD service. Many people use the first type to reset the root password, but the more recommended approach is the second one, that is, security is fast and easy.
Second, do not restart the Mysqld method
1, First of all, you have to have the right to modify the MySQL database account, the current MySQL instance account (lower permissions of the account, such as the test database can be modified) or other instances of the same version of the account. Copy the user table-related files below the Data/mysql directory to the Data/test directory.
Copy Code code as follows:
[Root@localhost mysql]# CP mysql/user.* test/
[Root@localhost mysql]# chown mysql.mysql test/user.*
2,Use another lower-privileged account link database to set the password data stored by the user in the test database.
Copy Code code as follows:
[Root@localhost mysql]# mysql-utest-p12345
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 17
Server Version:5.5.25a-log Source Distribution
Copyright (c), the Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark the Oracle Corporation and/or its
Affiliates. Names may trademarks of their respective
Owners.
Type ' help, ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
mysql> Use test
Reading table information for completion of table and column names
You can turn off the feature to get a quicker startup with-a
Database changed
mysql> Update user Set Password=password (' Yayun ') where user= ' root ';
Query OK, 0 rows Affected (0.00 sec)
Rows Matched:5 changed:0 warnings:0
Mysql>
3,Put the modified user. MyD and User.myi copied to the MySQL directory, remember to back up the files before.
Copy Code code as follows:
MV Mysql/user. MyD Mysql/user. Myd.bak
MV Mysql/user. Myi Mysql/user. Myi.bak
CP Test/user. my* mysql/
Chown Mysql.mysql mysql/user.*
4,Locate the MySQL process number and send a sighup signal to reload the permission table.
Copy Code code as follows:
[Root@localhost mysql]# pgrep-n MySQL
2184
[Root@localhost mysql]#
[Root@localhost mysql]# kill-sighup 2184
5,Landing test
Copy Code code as follows:
[Root@localhost mysql]# Mysql-uroot-pyayun
Welcome to the MySQL Monitor. Commands End With; or \g.
Your MySQL Connection ID is 20
Server Version:5.5.25a-log Source Distribution
Copyright (c), the Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark the Oracle Corporation and/or its
Affiliates. Names may trademarks of their respective
Owners.
Type ' help, ' or ' \h ' for help. Type ' \c ' to clear the current input statement.
Mysql>