Stop Mysql
systemctl stop mysqld
Set Mysql environment option
systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
Start Mysql
systemctl start mysqld
Login to Mysql as root
mysql -u root
Update the root user password
mysql> UPDATE mysql.user SET authentication_string = PASSWORD('MyPassword')
-> WHERE User = 'root' AND Host = 'localhost';
mysql> FLUSH PRIVILEGES;
mysql> quit
Stop mysql
systemctl stop mysqld
Unset the mySQL envitroment option so it starts normally next time
systemctl unset-environment MYSQLD_OPTS
Start mysql
systemctl start mysqld
Login to mysql again using your new password:
mysql -u root -p
NB : for 5.7.6 and later, you should use
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
Top comments (0)