There was a problem loading the comments.

How to Reset the MySQL root Password

Support Portal  »  Knowledgebase  »  Viewing Article

  Print

Quick answer: To reset a lost MySQL root password, stop the database, start it in a mode that skips permission checks, set a new password, then restart normally. On modern MySQL and MariaDB the cleanest method is the init-file approach. You need root or sudo access to the server.

Method: init-file (recommended)

Create a file, for example /tmp/reset.sql, with the new password:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewStrongPass123!';

Stop the service, then start it pointing at that file:

systemctl stop mysqld
mysqld --init-file=/tmp/reset.sql &

Once it starts, stop it, restart the service normally, and delete the file. On MariaDB use FLUSH PRIVILEGES; SET PASSWORD ... syntax if ALTER USER is unavailable.

Alternative: safe mode

Stopping the service and starting with --skip-grant-tables lets you connect without a password to set a new one. Because this disables authentication, allow no external connections while it is running, and re-enable grants immediately after.

Frequently asked questions

Is this safe on a live server?
Both methods briefly interrupt the database. Do it during a maintenance window and never leave skip-grant-tables running with the port exposed.

What if I only lost the application user password?
Log in as root and run ALTER USER for that account - no restart needed.

On a SoftSys managed Linux VPS our team can safely reset database credentials for you without risking downtime.


Share via
Did you find this article useful?  

Related Articles

Tags

© Softsys Hosting