MasterServerBlog › lost-mysql-password

How to Reset a MySQL Password

← all articles

Connect to your dedicated or virtual Linux server via SSH with root privileges, then enter the commands listed below in the console.

Resetting the MySQL root password over SSH

Stop mysql:
# /etc/init.d/mysql stop

Start mysql with parameters:
# mysqld_safe --skip-grant-tables &

Connect to the database server as the root user:
# mysql -u root

Set a new password:
mysql> use mysql;
mysql> update user set password=PASSWORD("NEW_PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit

Stop the mysql database server:
# /etc/init.d/mysql stop

Start the mysql database server:
# /etc/init.d/mysql start

Verify the new password:
# mysql -u root -p