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