Saturday, September 24, 2011

// // Leave a Comment

How to change a forgotten MySQL root password from SSH.

To change the MySQL root password, run the below commands as root:
/etc/init.d/mysql stop
killall -9 mysql 
/etc/init.d/mysql --skip-grant-tables --user=root start

Connect to mysql with the following command:
mysql -u root

Execute the below command in the mysql client: 
UPDATE mysql.user SET Password=PASSWORD('newpwd') WHERE User='root';

The 'newpwd' will be the new password for the MySQL.