How to reset the MySQL root user password when it can not log in

  1 min read  

When you forgot the mysql root password and can not log in to change the password.

Use sudo or root

  • You must first stop the mysql server
systemctl stop mysqld.service # systemd
rc-service mysql stop # openrc
  • Then you need to start the server in safe mode

    While running, DO NOT press control- {c, d, z}

mysqld_safe --skip-grant-tables
  • Now, open a new tab in the terminal, or a new terminal and enter MySQL
mysql -u root
  • And then change the MySQL root password
mysql> UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';
  • Okay, now just restart the MySQL server and login with the new password you used.

    After giving Ctrl + Z on the previous tab and kill the process, or simple exit and close the corresponding terminal or tab.

systemctl start mysqld.service # systemd
rc-update start mysqld.service # openrc
# Now login, normal user or root user
mysql -u root -p


Add our feed: to: