Skip to main content

Reset MySQL root password

Stop MySQL

systemctl stop systemctl stop mysqld

Set the MySQL environment option

systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

Start MySQL using the options you just set

systemctl start mysqld

Login as root

mysql -u root

For MySQL 5.7 or later

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

Or for lower versions

UPDATE mysql.user SET authentication_string = PASSWORD('MyNewPassword') WHERE User = 'root' AND Host = 'localhost';

Flush privilege 

FLUSH PRIVILEGES;
exit

Stop MySQL

systemctl stop mysqld

Unset the MySQL environment option so it starts normally next time

systemctl unset-environment MYSQLD_OPTS

Start MySQL

systemctl start mysqld