To reset MySQL 5.7 root password on CentOS 7 server, do the following
Stop MySQL Server
systemctl stop mysqld
Set the MySQL MYSQLD_OPTS environment to start MySQL with –skip-grant-tables
systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
Start MySQL with –skip-grant-tables
systemctl start mysqld
Login as user root
mysql -u root
Update MySQL root password
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NEW_MYSQL_PASSWORD_HERE';
Or
UPDATE mysql.user SET authentication_string = PASSWORD('NEW_MYSQL_PASSWORD_HERE') WHERE User = 'root' AND Host = 'localhost'; FLUSH PRIVILEGES;
Exit MySQL command prompt
quit
Stop MySQL server
systemctl stop mysqld
Unset the MySQL environment option
systemctl unset-environment MYSQLD_OPTS
Start MySQL normally
systemctl start mysqld
Now you should be able to log in with new MySQL root password using
mysql -u root -p
See Reset MySQL root password, mysql_safe: command not found
Leave a Reply