I have installed and reinstalled more times Mysql, but the program deny me always the access saying:

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

Event if I use the real password, there's no way to get into Mysql. Any suggestion? I'm thinking there's a problem with Grants, by I have no method see them, because they are in Mysql.

  • Did you tried to access without password? Typing only mysql ou mysql database_name? This is the new behaviour on newer versions (at least for MariaDB).
    – JucaPirama
    Apr 4, 2019 at 20:29
  • How did you install mySQL?
    – FloT
    Apr 4, 2019 at 21:02
  • I have installed mysql writing sudo apt-get install mysql-server, and then: sudo mysql_secure_installation. Apr 4, 2019 at 21:06

2 Answers 2


If you have installed mySQL from Ubuntu repository, the authentication of root user is not possible as usual with mysql -u root -p.

Instead, you have to type sudo mysql and the terminal will prompt you with your sudo password.

That should solve your problem and allow you to connect mySQL.

I had the same issue recently and I preferred getting back usual mysql -u root -p method (also easier to configure some tools e.g. mySQL Workbench, DBeaver...). Here are the steps I followed to get this done:

Connect to mySQL

sudo mysql

Create an admin account

CREATE USER 'admin'@'localhost' IDENTIFIED BY 'admin';

You can stop here and use the admin user instead of root. They basically have the same access rights.

If you prefer to come back to root user, you can follow the steps below: Quit root connection and reconnect with new admin account:

quit; /* mySQL will tell you "Bye" */
mysql -u admin -p

Remove root user

drop user root@localhost;

Re-create root user with usual authentication method

CREATE USER 'root'@'localhost' IDENTIFIED BY 'the_password_you_wish_here';

Then disconnect, re-connect with root and delete the admin account

quit; /* mySQL will tell you "Bye" */
mysql -u root -p
drop user admin@localhost;

Now you'll be able to connect with mysql -u root -p

  • I have tried the 'sudo mysql' but the answer is almost the same: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO). Apr 4, 2019 at 21:01
  • @GenginsKant You can refer to this answer on SO
    – Kulfy
    Apr 4, 2019 at 21:35
  • You have accepted this answer... Was it finally good or did the hyperlink given by @Kulfy solved your problem?
    – FloT
    Apr 5, 2019 at 7:38

Try this step by step first remove mysql from your machine then just install it by sudo apt-get install mysql-server you'll have ask to set a password.

sudo apt-get remove --purge mysql && sudo apt-get purge mysql && sudo apt-get autoremove && sudo apt-get autoclean && sudo apt-get remove dbconfig-mysql && sudo apt-get dist-upgrade && sudo apt-get install mysql-server

  • it does not ask me for a password, I have to write this: sudo mysql_secure_installation. Anyways It seems that I have found the solution, I have removed and reinstalled evrything. Problem was that I have to use the "sudo" before "mysql -u root -p". Apr 5, 2019 at 5:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .