Home >Database >Mysql Tutorial >What should I do if I forget the root password of mysql database under Linux?

What should I do if I forget the root password of mysql database under Linux?

青灯夜游
青灯夜游forward
2020-06-15 09:27:502888browse

What should I do if I forget the root password of mysql database under Linux?

mysql forget root password under linux

1. Close the mysql service

service mysqld stop

2. Modify the mysql configuration File

Modify /etc/my.cnf and add

skip-grant-tables ##忽略mysql权限问题,直接登录

after modification

What should I do if I forget the root password of mysql database under Linux?

# under the [mysqld] module ## 3. Start the mysql service and log in to the mysql database directly

At this time, you do not need a password to log in to the mysql database, you can log in directly

service mysqld start;
mysql -u root -p

4. Change the root password

mysql> update mysql.user set password=PASSWORD('new_password') where User='root'; 
mysql> flush privileges; 
mysql> quit;

5 , change my.cnf back, and then restart the mysql service

service mysqld restart;

6. Complete

Just log in with the new password

Recommended tutorial: "

mysql tutorial

The above is the detailed content of What should I do if I forget the root password of mysql database under Linux?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete