Solution to forgetting the root password of MySQL 5.7 and 8.0 database

Solution to forgetting the root password of MySQL 5.7 and 8.0 database

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!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • Tutorial on how to modify the root password in MySQL 5.7
  • How to reset the root password in mysql8.0.12
  • Summary of how to modify the root password in MySQL 5.7 and MySQL 8.0
  • Solution to the root password login problem in MySQL 5.7
  • A more elegant solution for forgetting the MySQL root password
  • mysql settings to change the root password, mysql server connection, mysql common commands diagram
  • Detailed explanation of the idea of ​​installing mysql8.0.11 and changing the root password and connecting navicat for mysql
  • Tutorial on installing and changing the root password of MySQL 5.7.20 decompressed version
  • Tutorial on resetting the root password of Mac MySQL

<<:  Native js to implement a simple calculator

>>:  Detailed explanation of installation and configuration of Redis and phpredis extension operation in Ubuntu 18.04 system

Recommend

Directory permissions when creating a container with Docker

When I was writing a project yesterday, I needed ...

JavaScript tips to help you improve your coding skills

Table of contents 1. Filter unique values 2. Shor...

Nginx installation detailed tutorial

1. Brief Introduction of Nginx Nginx is a free, o...

Using js to implement simple switch light code

Body part: <button>Turn on/off light</bu...

Instructions for using the meta viewport tag (mobile browsing zoom control)

When OP opens a web page with the current firmwar...

Tips on making web pages for mobile phones

Considering that many people now use smartphones, ...

CentOS 7 installation and configuration method graphic tutorial

This article records the detailed installation tu...

The difference between key and index in MySQL

Let's look at the code first: ALTER TABLE rep...

How to add docker port and get dockerfile

Get the Dockerfile from the Docker image docker h...

Using Docker to create static website applications (multiple ways)

There are many servers that can host static websi...