Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to deal with MySQL5.7 forgetting root password

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "how to deal with MySQL5.7 forgetting root password". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how MySQL5.7 forgets the root password".

When MySQL forgets the root password and cannot use the operating system authentication to go directly into the database to change the password, the root password needs to be reset.

1. Add a skip-grant-tables line to the configuration file / etc/my.cnf to skip password verification.

2. Restart the main process of mysql database # / etc/init.d/mysqld restart (you can also directly stop the MySQL process and restart MySQL using the skip-grant-tables parameter)

3. Log in to the database and change the password.

Mysql > update user set authentication_string=password ('') where user='root' and host='localhost'

Query OK, 1 row affected (0.00 sec)

Rows matched: 1 Changed: 1 Warnings: 0

Mysql > flush privileges

Query OK, 0 rows affected (0.00 sec)

Mysql >

Mysql > exit

The field that needs to be modified here is authentication_string, which is different from the previous version.

4. At this time, if the password you set is too simple, any command executed in the database will report an error similar to the following:

Mysql > show databases

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

Mysql > show database

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database' at line 1

Mysql > update user set authentication_string=password ('mysql') where user='root' and host='localhost'

ERROR 1046 (3D000): No database selected

Mysql > use mysql

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

5. Note: if you only want to set a simple password, you need to modify two global parameters:

Mysql > set global validate_password_policy=0

Mysql > set global validate_password_length=1

Mysql > set global validate_password_policy=0

Query OK, 0 rows affected (0.00 sec)

Mysql > set global validate_password_length=1

Query OK, 0 rows affected (0.00 sec)

Mysql > set password=password ("mysql")

Query OK, 0 rows affected, 1 warning (0.00 sec)

Mysql > use mysql

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with-A

Database changed

-End

At this point, I believe you have a deeper understanding of the "MySQL5.7 forgot root password processing", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report