Home  >  Article  >  Database  >  How to reset mysql user password?

How to reset mysql user password?

青灯夜游
青灯夜游forward
2020-06-15 09:18:532644browse

How to reset mysql user password?

mysql user password reset

Stop the MySQL service:

sudo service mysql stop

The above command applies to Ubuntu and Debian. Use mysqld to replace mysql under CentOS, Fedora and RHEL.
Start mysql in safe mode:

sudo mysqld_safe --skip-grant-tables --skip-networking &

So we can log in directly with root without a password:

mysql -u root

Reset password:

mysql> use mysql; mysql> update user set
password=PASSWORD("mynewpassword") where User='root'; mysql> flush
privileges;

Note, after the command A semicolon is required.

After the reset is complete, we exit and then start the mysql service:

mysql > quit

quit does not require a semicolon.

Restart the service:

sudo service mysql restart

Similarly, the above command is applicable to Ubuntu and Debian. Centos, Fedora and RHEL need to replace mysql with mysqld.

Recommended tutorial: "mysql tutorial"

The above is the detailed content of How to reset mysql user password?. 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