The MySQL Root Password Allows The Root User To Have Full Access To The MySQL Database. You Must Have (Linux) Root Administrator Access To The Server To Reset The MySQL Root Password.
 

Use The Following Steps To Reset A MySQL Root Password By Using The Command Line Interface.
 

Stop The MySQL Service

 

(Ubuntu And Debian) Run The Following Command:

sudo /etc/init.d/mysql stop


(CentOS, Fedora, And Red Hat Enterprise Linux) Run The Following Command:

sudo /etc/init.d/mysqld stop
 

Start MySQL Without A Password

 

Run The Following Command. The Ampersand (&) At The End Of The Command Is Required.

sudo mysqld_safe --skip-grant-tables &


Connect To MySQL

 

Run The Following Command:

mysql -uroot
 

Set A New MySQL Root Password

Run The Following Command:
 

use mysql;
update user set authentication_string=PASSWORD("mynewpassword") where User='root';
flush privileges;
quit


Stop And Start The MySQL Service

 

(Ubuntu And Debian) Run The Following Commands:

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


(CentOS, Fedora, And Red Hat Enterprise Linux) Run The Following Commands:

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

Log In To The Database

Test The New Password By Logging In To The Database.


mysql -u root -p


You Are Prompted For Your New Password.