How to Reset MySQL Root Password

If you are using linux and ever lose your MySQL root password or never set a root password and now unable to access it, so don’t worry, there is an easy way to reset MySQL root password. On all the modern Linux distribution you can recover the MySQL root password in just few easy steps.

How to Reset MySQL Root Password

1. Stop all the MySQL Processes

On Ubuntu and Debian distributions.

service mysql stop

On CentOS, Fedora and RHEL distributions.

service mysqld stop

2. Start MySQL Server with Safe Mode

mysqld_safe --skip-grant-tables &

3. Connect to the MySQL Server

mysql -u root

4. Setup a New MySQL Root Password

use mysql;
update user set password=PASSWORD("YourNewPassword") where User='root';
flush privileges;
exit

5. Stop MySQL Server and Start MySQL

On Ubuntu and Debian distributions.

service mysql stop
service mysql start

On CentOS, Fedora and RHEL distributions.

service mysqld stop
service mysqld start

Now you can test your new MySQL root password via logging in to it normally.

mysql -u root -p

After above command you will be prompted for new MySQL root password. You can verify it whether it is working or not in the shell.

This way you can reset MySQL root password and make it accessible again.

Share This

Author: AtulHost

Hi, I'm Atul Kumar Pandey, a full time blogger by passion and profession. Since I started working on the web industries many years ago, with my all expertise I blog on atulhost.com, where my main objective is to build and market quality contents and reviews.

4 thoughts on “How to Reset MySQL Root Password”

  1. Hi Atul, I have a problem because mine setup says “Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock'”.

    1. This error occurs due to multiple installations of mysql.

      Try a service restart or server reboot once. If you are still facing this issue even after restarting mysql services then run the following commands:

      ps -A|grep mysql

      Kill the process by using:

      sudo pkill mysql

      and then run command:

      ps -A|grep mysqld

      Also Kill this process by running:

      sudo pkill mysqld

      Now you are fully set just run the following commands:

      service mysql restart
      mysql -u root -p

      Now have very well working mysql again. Have a backup of your all database because nothing is more important than your precious data.

  2. Hi! Very good help, the only problem I have is that I don’t get MySQL to start. This is the error I get: Job for mariadb.service failed because a timeout was exceeded.

    See “systemctl status mariadb.service” and “journalctl -xe” for details. (And on top of that, my MySQL is named MariaDB for some reason?)

    1. Hi Melker, first of all, do not get confused with MySQL named as MariaDB it is a child of the same branch that follows the new rule (maybe you have installed or upgraded to MariaDB from MySQL).

      About the error, it seems to be an error with either permission or any app is creating a problem for MySQL to start. I will suggest to read the error log and find the culprit where it log will show something like “DENIED”. Then try to troubleshoot that error.

      TIP: If the error is about APPARMOR then quick fix is ln -s /etc/apparmor.d/usr.sbin.mysqld /etc/apparmor.d/disable/ and reboot.

Comments are closed.