Edit my.cnf file to allow an empty password
we /etc/my.cnf
In [mysqld] Insert: skip-grant-tables
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
Restart MySQL service
service mysqld restart
Log into the database using the mysql database, change the root password, exit the database
[root@localhost~]# mysql -u root
mysql> use mysql;
mysql> update user set authentication_string = password('m123'),password_last_changed=now() where user='root';
mysql> exit;
Open my.cnf again, the skip-grant-tables delete , save and exit
Mysql restart the service, you can use the database to reset the password
service mysqld restart