Reset a MySQL root password

So you've managed to misplace your root login for a MySQL database? Not to worry, the following procedure will guide you though resetting the root password on a MySQL database in 7 easy steps.

The MySQL root password is not the same as the system root password. If you have never set a root password for MySQL server, most likely it empty as MySQL does not require a password for database connections. However, it is HIGHLY recommended you set a password.

Steps to follow

Step 1

Login as root, then stop the MySQL server daemon.
# /etc/init.d/mysql stop

Step 2

Start the MySQL server without a password.
# mysqld_safe --skip-grant-tables &

Step 3

Connect to the MySQL server using the MySQL client.
# mysql -u root

Step 4

Set a new MySQL root user password by entering the following four commands. Be sure to change "NEW_ROOT_PASSWORD" to your desired password.
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW_ROOT_PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit

Step 5

Stop the MySQL server.
# /etc/init.d/mysql stop

Step 6

Now start the MySQL server.
# /etc/init.d/mysql stop

Step 7

Test to make sure your new MySQL root password works.
mysql -u root -p

  • 15 Users Found This Useful
Was this answer helpful?

Related Articles

Optimising Wordpress Blog

Every one loves wordpress and they enjoy working on it . However using a custom theme and plugins...

Internal Server Error while accessing cPanel, WHM & webmail

When accessing cPanel, WHM & webmail at times you get a error as below. Performing upcp OR...

How to Install LiteSpeed on a WHM/cPanel Server

Here’s how you install LiteSpeed on a WHM/cPanel Server – it should take about 25minutes from...

How to Create/Restore Backup In Kloxo

Backup/Restore is a core part of Kloxo. You can take backup of your entire hosting and you can...

Repairing a MySQL Database with phpMyAdmin

Occasionally database tables become corrupt and you are no long able to access them. It is a good...