Centos6.8 forget MySQL database root password solution

 

First, change the MySQL configuration file my.cnf, skip the password authentication.

Edit the configuration file /etc/my.cnf file in [mysqld] add the skip-grant-tables below, save and exit. Figure:

vim /etc/my.cnf

Save and exit.

Mysql restart service: service mysqld restart.

 

Second, enter the MySQL database, change the root password.

After the restart the MySQL service, use the mysql command to enter the MySQL command line, change the root password.

 

Change the root password:

mysql> UPDATE mysql.user SET Password = PASSWORD ( 'your password') where USER = 'root';

Note: You must use the PASSWORD () function encrypt passwords, login or not.

 

Refresh authority table:

mysql>flush privileges;

 

Exit Database:

exit

 

Third, delete or skip the password authentication configuration information commented, restart the MySQL service.

Revert to the original configuration: skip-grant-tables before you add or delete the configuration information commented.

vim /etc/my.cnf

Restart MySQL service: service mysqld restart

Guess you like

Origin www.cnblogs.com/xiaoFeng2017/p/11084937.html