Forgot the MySQL root password? Don't be afraid, teach you how to reset your 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 password

The --skip-grant-tables option means to skip the authorization table authentication when starting the MySQL service. After startup, the root connecting to MySQL will not require a password (dangerous).

[mysqld]

skip-grant-tables

2. Connect to MySQL with a root user with a blank password, and change the root 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.

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. Go to my.cnf and delete the skip-grant-tables option, and then restart the MySQL service.

At this point, the password of the root user of the MySQL database has been modified.

In addition, if you want to better improve your programming ability, learn C language and C++ programming! Overtaking in a curve, one step faster! I may be able to help you here~

Sharing (source code, actual project video, project notes, basic introductory tutorial)

Welcome partners who change careers and learn programming, use more information to learn and grow faster than thinking about it yourself!

Programming learning:

Programming learning:

Guess you like

Origin blog.csdn.net/weixin_45713725/article/details/114410164