In this tip we will see how to change or reset the MySQL root password under Ubuntu. This tip is tested under Ubuntu 11.10 and may work for other older versions of Ubuntu (11.04/10.10/10.04 or older).
This tutorial is also useful for users that forget to assign a MySQL root password during the installation of the MySQL client. If no password assigned, you may get this error when trying to login to the MySQL server:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
1. Open the terminal (Ctrl+Alt+T) and stop the MySQL server with this command:
sudo /etc/init.d/mysql stop
2. Run now this command to start the MySQL configuration:
sudo mysqld --skip-grant-tables &
3. Login now to the MySQL server as root:
mysql -u root mysql
4. Change now your MySQL root password with this command:
UPDATE user SET Password=PASSWORD('NEWPASSWORD') WHERE User='root'; FLUSH PRIVILEGES; exit;
Replace NEWPASSWORD with any password of your choice.
You can now login smoothly to the MySQL server with the assigned password.