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 mysql
to 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 root
recorded there, authentication_string
the 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