February 4, 2023

MySQL Reset root password

Steps

  1. Stop MySQL server
1
2
# cd to /etc/init.d check your mysql service name, in the original post is mysql but mine is mysqld
sudo /etc/init.d/mysqld stop
  1. Restart Mysql with --skip-grant-tables option
1
sudo mysqld_safe --skip-grant-tables &
  1. Connect to MySQL server using the mysql client
1
mysql
  1. Reload the grant tables so that account-management statements work
1
FLUSH PRIVILEGES;
  1. Change the 'root'@'localhost account password. Replace the password with the password that you want to use.
1
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
  1. Try to connect to MySQL using your new password
1
2
mysql -u root -p
$Password: Enter your new password here.

Something else

1
2
3
service mysqld status
service mysqld stop
service mysqld start


Reference

About this Post

This post is written by Andy, licensed under CC BY-NC 4.0.

#MySQL