Recover / Reset mysql database root password

Published on : April 27, 2026

Author:

Category: MySQL


For any reason, if you forget MySQL root password, you can reset the password by following way from shell access :-

Login as root to the linux/ubuntu machine with the MySQL server.

First stop the MySQL server

#/etc/init.d/mysql stop

Now you need to Start MySQL server without password

# mysqld_safe –skip-grant-tables &

Connect to mysql server using mysql client with the following command:

# mysql -u root

Now you should be having mysql prompt

mysql>

Now you need to Setup new MySQL root user password

mysql> use mysql;

mysql> update user set password=PASSWORD(“newrootpassword”) where user=’root’;

mysql> flush privileges;

mysql> quit

Note: Replace newrootpassword with the new root password for MySQL server.

Flush Privileges is needed to making the password change effect immediately.

Now you need to Stop MySQL Server using the following command:

# /etc/init.d/mysql stop

Test Your New Mysql root password

First you need to start mysql server using the following command:

# /etc/init.d/mysql start

# mysql -u root -p

Now it will prompt for root password and enter your new root password

Thank you

 

(Source: http://www.debianadmin.com/recover-mysql-database-root-password.html)

 

 


Leave a Reply

Your email address will not be published. Required fields are marked *