Centos under mysql8 forget the root password solution

First, open the configuration file /etc/my.cnf, add a line at the end:

skip-grant-tables

Then restart the mysql service:

service mysqld restart

You may then log in directly to mysql, at the input terminal mysqlto enter into mysql terminal.

In turn enter the following command:

use mysql;

select host, user, authentication_string, plugin from user;

You should see the user name rootrecorded there, authentication_stringthe field is a string of characters, that is, the root password encrypted string. First it empty:

update user set authentication_string='' where user='root';

And then change your password:

alter user 'root'@'%' identified by '你的新密码';

It should be noted here that, mysql8 the requirements of the password raised, must contain both uppercase and lowercase letters, numbers, special characters

Guess you like

Origin www.cnblogs.com/wuzhiblog/p/mysql8_change_root_password.html