Skip to Knowledge Base content

MariaDB (MySQL): Reset Lost Root Password

Derived from:  http://blog.dotkam.com/2007/04/10/mysql-reset-lost-root-password/

Here is a quick Step-by-Step “how to” which helps restoring MariaDB (MySQL) root password that was lost/forgotten.

 

1: Stop MariaDB (MySQL) daemon if it is currently running

Depending on the operating system MySQL is installed on, the daemon can be checked/stopped differently. Here is an example on how to do it in Unix-like systems.

 

NOTE: You might need to run it as a Unix System superuser (root) - depending on how the system is configured, and what permissions your Unix account is granted)

Here is how to stop/kill the existing MariaDB (mysql) daemon, in case it is running:

systemctl stop mariadb

2: Run MySQL safe daemon with skipping grant tables

mysqld_safe --skip-grant-tables &

3: Login to MySQL as root with no password

mysql -u root mysql

4: Run UPDATE query to reset the root password

In the MySQL command line prompt issue the following two commands:

UPDATE user SET password=PASSWORD("<a new password>") WHERE user="root";

FLUSH PRIVILEGES;

5: Stop and Restart the MariaDB daemon

systemctl stop mariadb (this will terminate the mysqld_safe executed in step 2 above)

systemctl start mariadb

Was this helpful?
0 reviews

Details

Article ID: 10895
Created
Tue 1/26/16 9:42 AM
Modified
Fri 4/7/17 8:41 AM