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

What if MySQL forgets his login password?

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

Share

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

This article mainly explains "what to do if MySQL forgets your login password". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what if MySQL forgets his login password"!

When taking over a project, it is a headache if the previous person in charge does not sort out the project documents and account passwords. For example, when you want to open the MySQL database, type:

Mysql-u root-p enter to enter the password, found that the password is wrong!

# [MySQL for Linux error ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)]

1. Find the location of the my.cnf configuration file

What is modified under windows is my.ini. Here we are mainly talking about the specific operation of Linux.

The Linux system can easily find the location of files using whereis:

$whereis my$ my:/etc/my.cnf

2. Modify my.cnf

If you are a root user, go directly to vim / etc/my.cnf (Note: my.ini is modified under windows)

If you are a regular user, sudo vim / etc/my.cnf

After entering the vim editor, find [mysqld], press the I key of the keyboard to enter edit mode, and add skip-grant-tables to any line after [mysqld] to skip the process of password verification:

Press ESC to exit editing, type: wq, enter to save and exit.

3. Restart the mysqld service

$sudo / etc/init.d/mysqld restart

Ordinary users add sudo at the beginning of this command, and root users do not need it.

4. Enter MySQL without secret

Ignore the occurrence of Entering password and enter to enter the MySQL database.

5. Modify the root password

After entering the MySQL database, we can update the password of the root record of the "user" table in the "mysql" database.

Mysql > use mysql;mysql > update user set password=password ('YOUR_NEW_PASSWORD') where user='root'; mysql > flush privileges

Step parsing:

Use mysql; enters a database named "mysql"

Then use the update statement to update the password

Use flush privileges; to refresh permissions after updating the password.

Note: the password () function is an encryption function for password storage, and the encryption process of this function is irreversible! So unless a large amount of data is used for comparison, there is no way to use any inverse function to view the old password, but to use this function to update the password. YOUR_NEW_PASSWORD is the new password set by yourself.

After setting the new password, Ctrl + D exits the MySQL database.

6. Reconfigure the my.cnf file

Re-open my.cnf with vim, delete the previous skip-grant-tables or precede it with a # comment, save and exit.

7. Restart the mysqld service

$sudo / etc/init.d/mysqld restart

8. Enter MySQL with a new password

Mysql-u root-p so far, I believe you have a deeper understanding of "MySQL forgot your login password". You might as well do it in practice. 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