Home > Database > Mysql Tutorial > How to reset mysql user password?

How to reset mysql user password?

青灯夜游
Release: 2020-06-15 09:18:53
forward
2739 people have browsed it

How to reset mysql user password?

mysql user password reset

Stop the MySQL service:

sudo service mysql stop
Copy after login

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

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

mysql -u root
Copy after login

Reset password:

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

Note, after the command A semicolon is required.

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

mysql > quit
Copy after login

quit does not require a semicolon.

Restart the service:

sudo service mysql restart
Copy after login

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!

Related labels:
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
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template