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

The solution of root password forgetting in MySQL version 5.7and 8.0 Database

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

Share

Shulou(Shulou.com)06/01 Report--

Note: MySQL5.7 cracked the root password, skipped password authentication to log in to the database, and directly changed the password in the table, but MySQL 8.0 can not change the root password in this way. After skipping password authentication and logging in to the database, you need to set the root password to null before logging in to the database and changing the root password.

1. Forget the root password solution of MySQL 5.7database 1 (recommended): [root@mysql ~] # systemctl stop mysqld # stop the MySQL service [root@mysql ~] # mysqld-- user=root-- skip-grant-tables # start the mysql service using the mysqld instruction, skip the authorization table # after the above command is executed, it will always occupy the current terminal, and you need to open another terminal. # Don't even think about running it in the background. [root@mysql ~] # ss-anpt | grep 3306 # open another terminal and make sure that the port is listening to LISTEN 080:: 3306: * users: (("mysqld", pid=8282,fd=33)) [root@mysql ~] # mysql-uroot # directly using root users to log in. No password required: mysql > update mysql.user set authentication_string=password ('1234')-> where User='root' and Host='localhost' # change the root password to "1234" mysql > flush privileges; # refresh permissions [root@mysql ~] # kill 8282 # kill off the terminal process number previously occupied when mysqld was started, do not use the-9 option [root@mysql ~] # systemctl start mysqld # to start the MySQL service, just log in with the new password

If the above process, the use of kill-9 to end the terminal occupied by mysqld, then starting again may report an error, sock file is locked, at this time, you need to delete your mysql sock file, my sock file here under / tmp, respectively, mysql.sock.lock and mysql.sock these two files, delete and start MySQL again.

Method 2: [root@mysql01 ~] # mysql-- version # determine MySQL version mysql Ver 14.14 Distrib 5.7.28 For linux-glibc2.12 (x86 / 64) using EditLine wrapper [root@mysql01 ~] # vim / etc/my.cnf # Edit the main configuration file [mysqld] # write the following under the line mysqld skip-grant-tables. # omit part of the content [root@mysql01 ~] # systemctl restart mysqld # restart the MySQL service Make the configuration file effective [root@mysql01 ~] # mysql-uroot # skip password verification, log in directly to the database # change the root password to pwd@123, and refresh permissions mysql > use mysql Mysql > update user set authentication_string = passwoord ('pwd@123') where user =' root';mysql > flush privileges # refresh permissions mysql > exit# configure password authentication Log in to [root@mysql01 ~] # vim / etc/my.cnf # to edit the main configuration file [mysqld] skip-grant-tables # delete this line [root@mysql01 ~] # systemctl restart mysqld # restart to make the change take effect # log in to [root@mysql01 ~] # mysql-uroot-ppwd@123 2, Forget the root password solution for MySQL 8.0 database [root@mysql01 ~] # mysql-- version # View MySQL version mysql Ver 8.0.18 for linux-glibc2.12 on x86x64 (MySQL Community Server-GPL) [root@mysql01 ~] # vim / etc/my.cnf # Edit the main configuration file [mysqld] # write the following content skip-grant-tables under the line mysqld. . # omit some content [root@mysql01 ~] # systemctl restart mysqld # restart the MySQL service Make the configuration file effective [root@mysql01 ~] # mysql-uroot # skip password verification and log in directly to the database # set the root password to empty mysql > use mysqlmysql > update user set authentication_string='' where user = 'root' Mysql > flush privileges;mysql > exit# enable password authentication and log back into the database [root@mysql01 ~] # vim / etc/my.cnf # Edit the main configuration file [mysqld] skip-grant-tables # delete this line [root@mysql01 ~] # systemctl restart mysqld # restart to make the changes take effect [root@mysql01 ~] # mysql-uroot # directly log in to the database mysql > alter user root@localhost identified by 'pwd@111';mysql > flush privileges Mysql > exit# login test with new password [root@mysql01 ~] # mysql-uroot-ppwd@111

-this is the end of this article. Thank you for reading-

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