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

systemctl stop mysqld

Set the MySQL MYSQLD_OPTS environment to start MySQL with –skip-grant-tables

Advertisement

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
Add a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Advertisement