How to reset the MySQL root password in Linux

How to reset mysql root password

Reset Mysql root password
Log in to your account using SSH
                  # ssh root@ip

Stop the MySQL server using the appropriate command for your Linux distribution

For CentOS and Fedora, type:

                  # service mysqld stop

For Debian and Ubuntu, type:

                  # service mysql stop
Restart the MySQL server with the —skip-grant-tables option. To do this, type the following command
                  # mysqld_safe --skip-grant-tables &
Log into MySQL using the following command
                  #
mysql
At the mysql> prompt, reset the password. To do this, type the following command, replacing
NEW-PASSWORD with the new root password

                  # UPDATE mysql.user SET Password=PASSWORD('NEW-PASSWORD') WHERE User='root';
At the mysql> prompt, type the following commands
                  # FLUSH PRIVILEGES;
                  # exit;
Stop the MySQL server using the following command. You will be prompted to enter
the new MySQL root password
                  #
mysqladmin -u root -p shutdown
Start the MySQL server normally

      For CentOS and Fedora, type:

                  # service mysqld start

                  #
For Debian and Ubuntu, type:   
mysql start
service

Blog type: 

Add new comment

Authored By

swati sharma

Am working in HCL since 2 yr. i am RHCE certified engineer, working since 4 yr as a Network Admin.

Follow us on

Facebook​  Twitter  LinkedIn  Google+