Home >Database >Mysql Tutorial >What should I do if I forget mysql password?

What should I do if I forget mysql password?

青灯夜游
青灯夜游Original
2022-02-21 15:15:51114964browse

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

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.

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

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!

Statement:
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