Linux forgot root password modification method

Forgot password (change password) 
1. Modify the my.cnf configuration file 
vim /etc/my.cnf, 
add skip-grant-tables in the blank space under [mysqld], then save and exit with wq 



2. Then restart the MySQL service 
systemctl restart mysqld 

3. Enter the database, select the data mysql and refresh the permissions 
 mysql -u root -p; 
 use mysql; 
 flush privileges; 

4. Then change the password 
ALTER USER 'root'@'localhost' IDENTIFIED BY 'the password you want to change'; 

if an error message is displayed: ERROR 1396 (HY000): Operation ALTER USER failed for 'root'@'localhost'This 
may be that the address where root is located is wrong, root'@'localhost Here localhost may be %Query 

statement: 
use mysql; 
select user,host from user where user='root'; 

modify the sql statement to change the password: 
ALTER USER 'root'@'%' IDENTIFIED BY 'the password you want to modify'; you can 

flush privileges;

 5. Go to the configuration file my.cnf to delete skip-grant-tables, save and exit, then restart mysql to successfully change the password

systemctl restart mysqld Finally restart mysqld

Guess you like

Origin blog.csdn.net/weixin_55944621/article/details/128000451