MySQL gets installed with a default root account under the username “root”. Sometimes the system will allow you to install a root account without a password (VERY not safe), but for the most part you have to set a password on install.

If of course you are anything like me, you instantly forget this password and a month down the line when you come back to do some more tinkering, you’ll quickly realize that you need to change the damn password – and this is one way you could go about doing it!

First, stop the MySQL server by entering the following into a terminal:

sudo /etc/init.d/mysql stop

Next, start a custom mysqld configuration by skipping the password tables:

sudo mysqld –skip-grant-tables &

The next step is then to login as root:

mysql -u root mysql

Finally, replace the existing password with your new one and Bob’s your uncle!

UPDATE user SET Password=PASSWORD(‘YOURNEWPASSWORD’) WHERE User=’root’; FLUSH PRIVILEGES; exit;

Done. Oh, and don’t forget to restart the service with sudo /etc/init.d/mysql start if necessary.

(Ubuntu 10.10 Maverick Meerkat)