Unable to access SQL database

Posted January 24, 2017 4.1k views
MySQLUbuntu 16.04


For some reason, I’m unable to access SQL on my host:

mysql -u root -p

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

The password is correct I believe, and I’m logged into 'root’ rather than my regular login.

Hope you can help

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
4 answers

The password is not correct.

If that’s the case, how is it reset?


The root password for SSH and the root password for MySQL will/should be different, so just because you’re logged in as root via SSH doesn’t mean you’ll be able to login as root to MySQL.

If you installed MySQL from the CLI using a command such as:

apt-get install -y mysql-server


apt-get install -y mariadb-server

The root password for MySQL is set one of two ways.

  • You’ll be prompted to set a password during installation of the package or;
  • You’ll need to run mysql_secure_installation and set the password when prompted.

That doesn’t work either. When installing mysql-server, it doesn’t prompt to set a password, and when running mysqlsecureinstallation it asks for a password, which throws the same error:


Securing the MySQL server deployment.

Enter password for user root:
Error: Access denied for user ‘root’@'localhost’ (using password: YES)