Ask a question »

MySQL - Reset the root password

August 2015

For users of the powerful database MySQL, access, as well as right to modify the admin (root) password is important, because both are required when installing and in situations when the master password is lost. The user must be connected to the root password to modify it but for reinitialising the password, this process can be skipped. Resetting the password is possible after connection to the MySQL database with the help of specific commands. In case the password is lost, then it is also possible to get access to the MySQL server through a bypass of the authentication process. To reset the password under the latter condition, the server must be restarted to continue the process.


Issue: Root password is lost


To modify the existing root password, you must firstly be connected to the account. If you know the root password and just want to reinitialize it, you can skip this part. If you don't have the root password then follow the steps below:
  • Stop the MySQL server
    • #/etc/init.d/mysql stop
  • Restart MySQL, disabling network communication and skipping the authentication procedure
    • #mysqld --skip-grant-tables --skip-networking &

Resetting the password

  • Get connected to the MySQL system database:
    • # mysql mysql -u root
  • Type in the following command and reset your password:
    • UPDATE user SET password=PASSWORD('newpassword') WHERE user="root";
  • If you didn't go through the first step, to validate the changes simply type:
    • FLUSH PRIVILEGES;
  • If you started MySQL manually (bypassing the authentication process), the server must be restarted:
    • #/etc/init.d/mysql restart
Note that: Changing your password can cause connection problems between phpmyadmin and mysql.
For unlimited offline reading, you can download this article for free in PDF format:
Mysql-reset-the-root-password.pdf

See also

In the same category

Reinicializar la contraseña de root de MySQL
By Carlos-vialfa on January 13, 2009
MySQL - Changer le mot de passe root
By Jeff on March 12, 2008
My SQL - Reinicializar a senha do roteador
By pintuda on March 20, 2012
Original article published by Jeff. Translated by jak58. - Latest update by deri58
This document entitled « MySQL - Reset the root password » from CCM (ccm.net) is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.