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

Nginx Layer 4 Load Balancing Configuration Guide

1. Introduction to Layer 4 Load Balancing What is...

Example of using swiper plugin to implement carousel in Vue

Table of contents vue - Use swiper plugin to impl...

Steps and pitfalls of upgrading linux mysql5.5 to mysql5.7

Table of contents Linux MySQL 5.5 upgraded to MyS...

Problems and solutions when replacing Oracle with MySQL

Table of contents Migration Tools Application tra...

Detailed tutorial on deploying Jenkins based on docker

0. When I made this document, it was around Decem...

Detailed explanation of the difference between uniapp and vue

Table of contents 1. Simple page example 2.uni-ap...

MySql quick insert tens of millions of large data examples

In the field of data analysis, database is our go...

Create a code example of zabbix monitoring system based on Dockerfile

Use the for loop to import the zabbix image into ...

TinyEditor is a simple and easy-to-use HTML WYSIWYG editor

A few days ago, I introduced to you a domestic xh...

Detailed explanation of nginx shared memory mechanism

Nginx's shared memory is one of the main reas...

MySQL 5.7.16 free installation version graphic tutorial under Linux

This article shares the MySQL 5.7.16 free install...

mysql data insert, update and delete details

Table of contents 1. Insert 2. Update 3. Delete 1...

Vue+flask realizes video synthesis function (drag and drop upload)

Table of contents We have written about drag and ...