Here are the steps to change or reset or set your MySQL password on a Ubuntu 11.10 or Linux machines.
1. Stop the mysql server using the following command:
sudo /etc/init.d/mysql stop
2. Start the mysqld demon process using the –skip-grant-tables option with the following command:
sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking &
3. Start the mysql client using the following command:
mysql -u root
4. From the mysql prompt execute the following command to be able to change any password:
FLUSH PRIVILEGES;
5. Then reset/update your password:
SET PASSWORD FOR root@'localhost' = PASSWORD('YOURNEWPASSWORD');
6. If you have a mysql root account that can connect from everywhere, you should also do:
UPDATE mysql.user SET Password=PASSWORD('YOURNEWPASSWORD') WHERE User='root';
or
5. Alternate Method to reset/update your password:
USE mysql
UPDATE user SET Password = PASSWORD('YOURNEWPASSWORD') WHERE Host = 'localhost' AND User = 'root';
6. And if you have a root account that can access from everywhere:
USE mysql
UPDATE user SET Password = PASSWORD('newpwd') WHERE Host = '%' AND User = 'root';
For either method, once have received a message indicating a successful query (one or more rows affected), we need to flush privileges:
FLUSH PRIVILEGES;
Come out of mysql environment using:
exit;
Finally, we need to stop the mysqld
process and restart it:
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start
References
MysqlPasswordReset – Community Ubuntu Documentation
MySQL 5.0 Reference Manual: How to Reset the Root Password
Cheers 🙂