Note: To crack the root password in MySQL5.7, you can skip password authentication and log in to the database, and directly modify the password in the table. However, you cannot modify the root password in this way in MySQL 8.0. You need to skip password authentication and log in to the database, set the root password to empty first, and then you can log in to the database and modify the root password. 1. Solution to forgetting the root password of MySQL 5.7 database [root@mysql01 ~]# mysql --version #Determine the 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 content under the mysqld line skip-grant-tables .................#Omit some content[root@mysql01 ~]# systemctl restart mysqld #Restart the MySQL service to make the configuration file effective[root@mysql01 ~]# mysql -uroot #Skip password verification and log in to the database directly#Change the root password to pwd@123 and refresh the permissionsmysql> use mysql; mysql> update user set authentication_string = passwoord('pwd@123') where user = 'root'; mysql> flush privileges; #Refresh privilegesmysql> exit #Configure password verification and log in with the new password [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 #You can successfully log in using the new password [root@mysql01 ~]# mysql -uroot -ppwd@123 2. Solution to forgetting the root password of MySQL 8.0 database [root@mysql01 ~]# mysql --version # View MySQL version mysql Ver 8.0.18 for linux-glibc2.12 on x86_64 (MySQL Community Server - GPL) [root@mysql01 ~]# vim /etc/my.cnf #Edit the main configuration file [mysqld] #Write the following content under the mysqld line skip-grant-tables .................#Omit some content[root@mysql01 ~]# systemctl restart mysqld #Restart the MySQL service to make the configuration file effective[root@mysql01 ~]# mysql -uroot #Skip password verification and log in to the database directly#Set the root password to emptymysql> use mysql mysql> update user set authentication_string='' where user = 'root'; mysql> flush privileges; mysql> exit # Enable password verification and re-login to 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 #Log in to the database directly mysql> alter user root@localhost identified by 'pwd@111'; mysql> flush privileges; mysql> exit #Login test using the new password [root@mysql01 ~]# mysql -uroot -ppwd@111 Summarize The above is the solution to the forgotten root password of MySQL 5.7 and 8.0 version database introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website! You may also be interested in:
|
<<: Native js to implement a simple calculator
1. Introduction to Layer 4 Load Balancing What is...
Table of contents vue - Use swiper plugin to impl...
Table of contents Linux MySQL 5.5 upgraded to MyS...
Table of contents Migration Tools Application tra...
When developing a web project, you need to instal...
0. When I made this document, it was around Decem...
Table of contents 1. Simple page example 2.uni-ap...
In the field of data analysis, database is our go...
Use the for loop to import the zabbix image into ...
A few days ago, I introduced to you a domestic xh...
Nginx's shared memory is one of the main reas...
This article shares the MySQL 5.7.16 free install...
Execute the command: docker run --name centos8 -d...
Table of contents 1. Insert 2. Update 3. Delete 1...
Table of contents We have written about drag and ...