Ubuntu – MySql – unable to connect as root


I have need to connect to mySql server 5.5 and create database using command line. Ideally it would be using a UI utility but I don't have it. Here is an issue:

alex@ubuntu:~$ sudo mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

However I definitely set password while I was installing MySql server.

What should I do to solve it?

Best Answer

Connect with sudo mysql -u root -p and it will prompt you for the password. The key here is the -p option. You can also provide the password as part of the command with the -p option, but that is considered a security risk, since the password will be stored in clear text in your commands history.