How to change MySQL root password?
Debian, Ubuntu, Fedora, CentOS

This post shows how you can change your MySQL root password.

1. FIND ROOT USERNAME

The root username is always root.

2. HOW TO CHANGE DEFAULT ROOT PASSWORD

Connect to your server, using command line (terminal), then run:

2.1. Stop MySQL:

If you are using Ubuntu or Debian:

sudo /etc/init.d/mysql stop

For CentOS, Fedora, and RHEL:

sudo /etc/init.d/mysqld stop

2.2. Start MySQL in safe mode:

sudo mysqld_safe –skip-grant-tables &

2.3. Login (without any password):

mysql -u root

2.4. Select the database:

use mysql;

2.5. Change password:

update user set password=PASSWORD(“YOUR NEW PASSWORD HERE”) where User=’root’;

2.6. Flush Privileges (a refresh for privileges):

flush privileges;

2.7. Exit:

quit

or

exit

2.8. Restart MySQL:

Ubuntu and Debian:

sudo /etc/init.d/mysql stop
and
sudo /etc/init.d/mysql start

CentOS, Fedora and RHEL:

sudo /etc/init.d/mysqld stop
and
sudo /etc/init.d/mysql start

Password changed successfully!

Now, you can try to login with the new password:

mysql -u root -p

*(type the password when prompted)*

Success!

If you need a reliable Dedicated Server or VPS, you should definitely try InterServer Hosting. You can test InterServer for 1 Penny, for the first month, using this coupon code: WSG1PENNY.