I installed MySQL server on an Amazon EC2 instance and started it. Seems like it started, but when I try to do mysql -u root I get this error.

mysql -u root

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using       password: NO)

I don't have a password for the root and don't know how to go forward. How do I access the new installation?


While others are suggesting a full reset of the MySQL root password via launching into single user mode and then reseting the password manually through a query, that should not be the case on a clean install.

And though this question is from 2015, it’s unclear what version of MySQL is being used. So that said, using MySQL 5.7, the process of getting a password on a clean install has changed. A temporary password is now set in the MySQL daemon log file which should be in this location:


But could also be in this path:


As explained here in the official MySQL 5.7 docs the password is in that error log and can be found using Grep like this:

grep 'temporary password' /var/log/mysqld.log

You can now login to MySQL using that password by running this command and entering that password when prompted:

mysql -uroot p

Or you can run mysql_secure_installation—which is good practice regardless—and enter and change the password there with that.

| improve this answer | |

The only way to get the password reset is as follow:

service mysql stop
service mysql start --skip-grant-tables

Once logged in, set the password like this

UPDATE mysql.user SET password=PASSWORD('whateverpassword')
WHERE user='root' and host='localhost';

Exit mysql client, and run

service mysql restart

That's it. You could now login with root@localhost's new password

mysql -uroot -p
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.