This method is available for unknown database password or initial login:
If you change the password, you should stop the MySQL service first.
Systemctl Stop Mysqld
1 Modify the configuration file, skip the password to enter the database
Vim/etc/my.cnf
[Mysqld]
Skip-grant-tables
Restart Service:
Systemctl Restart Mysqld
Enter the database:
Mysql
To view the database table structure:
Desc Mysql.user;
Set Database login Password
Update Mysql.user Set Authentication_string=password ("123456");
Exit
Quit
Modify the configuration file again, comment out the skipped password, then write two lines
[Mysqld]
#skip-grant-tables
Validate_password_policy=0
Validate_password_length=6
Restart Service
Systemctl Restart Mysqld
Log in to the database with a set password
mysql-uroot-p123456
show databases;
The user is required to write the password again at this time
Set password for [email Protected]=password ("123456");
Exit
Quit
Re-entry
mysql-uroot-p123456
The database is working correctly:
show databases;
MySQL Database Password modification