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?

青灯夜游
Release: 2020-06-15 09:27:50
forward
2898 people have browsed it

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
Copy after login

2. Modify the mysql configuration File

Modify /etc/my.cnf and add

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

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
Copy after login

4. Change the root password

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

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

service mysqld restart;
Copy after login
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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template