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 I forget my MySQL password?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

This article shows you how to forget the MySQL password, the content is concise and easy to understand, it will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.

2.1.Boot in skip-grant-tables mode

Skip-grant-tables said that when starting mysql, the authorization table function is not started, and you can log in directly without a password.

# modify / etc/my.cnf file vim / etc/my.cnf # add configuration in [mysqld] area, and save my.cnf file skip-grant-tables # restart mysql systemctl restart mysqld # login mysql mysql-u root-p # if you enter a password and enter directly, you can enter the database.

2.2. Modify the root password

# Log in to mysql and have not entered the database at this time. Use the following command use mysql; # to change the root password (mysql5.7 version) update user set authentication_string = password ('password'), password_expired = 'now () where user='root'; # if your mysql is version 5.6, modify the root password (mysql5.6 version) update user set password=password (' password') where user='root'; # to make it effective flush privileges # exit exit

2.3. Add administrator users

If you do not want to change the root password, you can add an administrator user as follows:

# Log in to mysql, and before entering the database, use the following command use mysql; # refresh the database flush privileges; # to create a user and give the administrator permission to grant all privileges on *. * to 'user' @'% 'identified by' password'; # for example, create an admin user with the password of admin grant all privileges on. * to 'admin'@'%' identified by' admin'

2.4. Restart the server

After the above operation is completed, it is not finished yet. You need to turn off the authorization table function and restart the server.

# modify / etc/my.cnf file vim / etc/my.cnf # delete the configuration in the [mysqld] area, and save the my.cnf file # skip-grant-tables # restart mysql systemctl restart mysqld # at this time, the modification is finished

Third, test the connection

Test login using the admin user we just created

# admin login mysql-u admin-p # enter password admin, you can log in at this time

IV. Summary

If you also forget your password, you can use this method to solve the current problem.

After the mysql5.7.6 version, the password () method in the user table is discarded, so the old method of resetting the password does not work for the mysql8.0 version!

Mysql8 can use this method to change the root password:

# in skip-grant-tables mode, leave the root password blank update user set authentication_string =''where user =' root'; # exit, remove the skip-grant-tables under / etc/my.cnf file, restart the server # log in to mysql mysql-u root-p # because the password is empty, enter directly and enter the database, change the password ALTER USER 'root'@'localhost' IDENTIFIED BY' Hello@123456' # because of mysql8, strong check is used, so if the password is too simple, an error will be reported, and the password will be as complicated as possible! The above content is what to do if you forget your MySQL password. Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

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