How to reset Mysq8l if you forget the root password after installing it on Centos

Scenes

Forgot root password during Mysql8 offline installation on Windows:

Mysql8 forgets root password during offline installation on Windows - CSDN Blog

If you forget your password on Windows, you can refer to the above.

If you install mysql in Centos, you can refer to the following.

Install Mysql8 in CentOS7 and configure remote connection, change password, etc.:

Install Mysql8 in CentOS7 and configure remote connection, change password, etc._centos7 mysql8 change password_Domineering and Rogue Temperament Blog-CSDN Blog

If you forget the root password after installing msyql in Centos as above, you can reset it like this

Note:

Blog:
Domineering hooligan temperament_C#, architecture road, SpringBoot-CSDN blog

accomplish

1. Stop the mysql service

systemctl stop mysqld

2. Start mysql in safe mode

mysqld_safe --skip-grant-tables &

3. Modify the mysql configuration file

nano /etc/my.cnf

Add the following under [mysqld] in the configuration file to skip password verification

skip-grant-tables

To operate nano, use ctrl+o to save the file, and use ctrl+x to exit nano.

4. Restart the mysql service

systemctl start mysqld

After entering the mysql command line, execute the statement to reset the password

FLUSH PRIVILEGES;

ALTER USER 'root'@'localhost' IDENTIFIED BY 'Aa_123456';

FLUSH PRIVILEGES;

The password must be complex and contain uppercase and lowercase letters, symbols and numbers, otherwise you will be prompted:

Your password does not satisfy the current plicy requirements

5. Restore the mysql configuration file and remove the configuration to skip password verification added above.

Then stop the mysql service

systemctl stop mysqld

Start the mysql service again

systemctl start mysql

If prompted at this time:

Job for mysql.service failed because the control process exited with error code ,See "systemctl status mysqld.service" and

"journalctl -xe" for details.

Then follow the prompts to view

systemctl status mysqld.service

One reason here is that the memory and disk space allocated by the virtual machine are too small. It may also be caused by other reasons. It is for reference only.

6. After allocating large memory and hard disk space and restarting the virtual machine, the connection to mysql is successful.

Guess you like

Origin blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/134683487