Home > Database > Mysql Tutorial > body text

What should I do if I forget mysql password?

青灯夜游
Release: 2022-02-21 15:15:55
Original
114921 people have browsed it

Solution: 1. Open the configuration file "my.cnf", add the "skip-grant-tables" statement under the "[mysqld]" item, and restart the MySQL service; 2. Execute "mysql -u root " command to log in to the database without a password; 3. Use the update command to reset the login password.

What should I do if I forget mysql password?

The operating environment of this tutorial: windows7 system, mysql8 version, Dell G3 computer.

What should I do if I forget mysql password? Don’t be afraid, you can reset a new password through Reset password,

How to reset password

1. Modify the configuration file my.cnf, add skip-grant-tables under the configuration file [mysqld], restart the MySQL service to log in without a password

among them --skip-grant-tables The option means to skip the permission table authentication when starting the MySQL service. Once started, root connections to MySQL will not require a password (dangerous).

[mysqld]
skip-grant-tables
Copy after login

2. Connect to MySQL with the root user with an empty password, and change the root password

Log in to the MySQL database without a password:

[root@iZ235wguph2Z www]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 295
Server version: 5.0.56-log Source distribution
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
Copy after login

Reset Password:

mysql> update user set password=password('123456') where User='root';
ERROR 1046 (3D000): No database selected
mysql> use mysql;
Database changed
mysql> update user set password=password('123456') where User='root';
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Copy after login

3. Delete the skip-grant-tables option in my.cnf, and then restart the MySQL service.

The password of the root user of the MySQL database has been modified.

[Related recommendations: mysql video tutorial]

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

Related labels:
source:php.cn
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