Reset MySQL Root Password in Centos 7

Last updated on Dec 27, 2019 in MySQL, Linux

Resetting the MySQL root password in CentOS 7 is straight-forward.

Stop MySQL Server

sudo systemctl stop mysqld

Start MySQL Server In Safe Mode

sudo mysqld_safe --skip-grant-tables &

After the server has started, and if looks like it is hanging, press enter and the command prompt should become available again.

Connect to MySQL as Root

mysql -uroot

Change the Root Password

use mysql;
update user set authentication_string=PASSWORD("mypassword") where User='root';
flush privileges;

Restart the MySQL Server

sudo systemctl stop mysqld
sudo systemctl start mysqld

Log In To MySQL Normally

mysql -uroot -p

You should now be able to use your new password.