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 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.
People reacted to this story.
Show comments Hide comments[…] After running the above command in a Terminal, open another Terminal window and run the command below which will open up MySQL console making it easier for you to update your MySQL root user. […]