MySQL on Ubuntu – Unable to Set MySQL Root Password

linuxMySQLUbuntu

After installing mysql on Ubuntu (10.4), when I try to set the root password (sudo mysqladmin password NEW_PASSWORD) I get the following error:

mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: NO)'

Anyone knows what's going on?

Best Answer

Your mysql database already has a root password. It was probably set when you installed mysql.

If you know the existing password, use this:

sudo mysqladmin -p password NEW_PASSWORD

The '-p' will tell mysql to prompt you to enter your old password first. Then, it will replace the existing password with the string NEW_PASSWORD.

If you do not remember the original password, you'll need to shut it down and start it following the instructions at http://www.cyberciti.biz/tips/recover-mysql-root-password.html . This is easy to do, but does require some downtime.

UPDATE

Another option.

You can tell Ubuntu to reconfigure your MySQL server. This will reconfigure mysql-server-5.1 from scratch, and will ask you for a new password from the root user. Caution: This will completely wipe out any existing data, and will replace them with the default data. However, I'm guessing your database doesn't contain anything.

sudo dpkg-reconfigure mysql-server-5.1

(If I remember right, Ubuntu 10.04 comes with MySQL server 5.1, not 5.0)