Reset MySQL password in CentOS

SSH to your server and perform the below-mentioned steps to get your MySQL root password reset.

* Stop MySQL service
# /etc/init.d/mysqld stop


Stopping MySQL database server: mysqld.

* Now, start MySQL server without password using the below command
# mysqld_safe –skip-grant-tables &


[1] 5988
Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe[6025]: started

* Connect to MySQL server using the following command.
#  mysql -u root


Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

* Then you will enter into the MySQL prompt.

* In order to reset the root password, you can run the following mysql commands in the mysql prompt.

mysql> use mysql;
mysql> update user set password=”new root password’ where user=’root’;
mysql> flush privileges;
mysql> quit;

* Now, stop MySQL server
# /etc/init.d/mysqld stop


Stopping MySQL database server: mysqld
STOPPING server from pid file /var/run/mysqld/
mysqld_safe[6186]: ended
[1]+  Done

*Start MySQL server and test it
# /etc/init.d/mysql start
# mysql -u root -p