Question

Setup MySQL on Ubuntu Droplet getting error ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

  • Posted December 3, 2015
  • MySQL

Hi guys, I am very new to using a service like digitalocean (opposed to a one click setup of mediatemple or godaddy) and I am trying to setup and configure a new DB using MySQL but I keep getting the error

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

I have googled this, and searched the community for answers but cannot seem to solve this issue. Am I missing something? I have tried running it as root, and running it with sudo through another user and cannot get around it. If I offer no password it gives the same error but instead of using password: YES, it’s NO.

Thanks.

Subscribe
Share

Am using Ubuntu-16.04 : installed mysql - 5.7. I Had the same issue.

Tried the below steps:

  1. dpkg --get-selections | grep mysql (to get the version of mysql).

  2. dpkg-reconfigure mysql-server-5.7

  3. mysql -u root -p

Without -p that doesn’t prompt you to ask password. Once you are in, you can create a user with a password by following steps :

CREATE USER ‘-your_name-’@‘your-hostname’ IDENTIFIED BY ‘your-password’;

GRANT ALL PRIVILEGES ON . to ‘-your_name-’@‘your-hostname’ WITH GRANT OPTION;

Exit from the root and login from the you gave above.

mysql -u -p

For some reason still just typing mysql does not work. AT ALL. Please let me know if this works, else I have other steps.

Am using Ubuntu-16.04 : installed mysql - 5.7. I Had the same issue.

Tried the below steps:

  1. dpkg --get-selections | grep mysql (to get the version of mysql).

  2. dpkg-reconfigure mysql-server-5.7

  3. mysql -u root -p

Without -p that doesn’t prompt you to ask password. Once you are in, you can create a user with a password by following steps :

CREATE USER ‘-your_name-’@‘your-hostname’ IDENTIFIED BY ‘your-password’;

GRANT ALL PRIVILEGES ON . to ‘-your_name-’@‘your-hostname’ WITH GRANT OPTION;

Exit from the root and login from the you gave above.

mysql -u -p

For some reason still just typing mysql does not work. AT ALL. Please let me know if this works, else I have other steps.

O/S: Ubuntu 16.04 64bit App: MySQL Command entered: sudo mysql -u root Error:ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)

I have reimaged 3 times following instructions on the installation, have given it a password and still get this error.

When I try the step below: mysql -uroot I get this error:ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)

any help would be greatly appreciated

Experienced the same problem. This particular explanation and solution made sense for me and helped as well: http://stackoverflow.com/questions/10299148/mysql-error-1045-28000-access-denied-for-user-billlocalhost-using-passw

Same solution, just login as root and then change password of the user:

update user set password=PASSWORD("YOURPASSWORDHERE") where User='user02';

Thanks for your solution that worked for me … I made the mistake to alter my setup with security check my mysql installation. THANKS again

I faced like this error while i want check my database ERROR 1045 (28000): Access denied for user ‘user02’@‘localhost’ (using password: NO) do you have solution about this


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

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.

On MySql 5.7 version you must replace query to:

 update user set authentication_string=PASSWORD("YOURPASSWORDHERE") where user="root"; 

everything else it’s like CrypticDesigns described…

On MySql 5.7 version you must replace query to:

 update user set authentication_string=PASSWORD("YOURPASSWORDHERE") where user="root"; 

everything else it’s like CrypticDesigns described…

Which one-click-setup did you use? You can check the configuration files probably and find the password. If you can’t find it, neither root without pass is working you can reset it:

Commands

sudo /etc/init.d/mysql stop

Now start up MySQL in safe mode, so you’ll skip the privileges table:

sudo mysqld_safe --skip-grant-tables &

Login with root:

mysql -uroot

And assign the DB that needs to be used:

use mysql;

Now all you have to do is reset your root password of the MySQL user and restart the MySQL service:

update user set password=PASSWORD("YOURPASSWORDHERE") where User='root';
flush privileges;

quit and restart MySQL:

quit
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

Now your root password should be working with the one you just set, check it with:

mysql -u root -p

Hope this will help you figure it out.

Which one-click-setup did you use? You can check the configuration files probably and find the password. If you can’t find it, neither root without pass is working you can reset it:

Commands

sudo /etc/init.d/mysql stop

Now start up MySQL in safe mode, so you’ll skip the privileges table:

sudo mysqld_safe --skip-grant-tables &

Login with root:

mysql -uroot

And assign the DB that needs to be used:

use mysql;

Now all you have to do is reset your root password of the MySQL user and restart the MySQL service:

update user set password=PASSWORD("YOURPASSWORDHERE") where User='root';
flush privileges;

quit and restart MySQL:

quit
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

Now your root password should be working with the one you just set, check it with:

mysql -u root -p

Hope this will help you figure it out.

Which one-click-setup did you use? You can check the configuration files probably and find the password. If you can’t find it, neither root without pass is working you can reset it:

Commands

sudo /etc/init.d/mysql stop

Now start up MySQL in safe mode, so you’ll skip the privileges table:

sudo mysqld_safe --skip-grant-tables &

Login with root:

mysql -uroot

And assign the DB that needs to be used:

use mysql;

Now all you have to do is reset your root password of the MySQL user and restart the MySQL service:

update user set password=PASSWORD("YOURPASSWORDHERE") where User='root';
flush privileges;

quit and restart MySQL:

quit
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

Now your root password should be working with the one you just set, check it with:

mysql -u root -p

Hope this will help you figure it out.

Which one-click-setup did you use? You can check the configuration files probably and find the password. If you can’t find it, neither root without pass is working you can reset it:

Commands

sudo /etc/init.d/mysql stop

Now start up MySQL in safe mode, so you’ll skip the privileges table:

sudo mysqld_safe --skip-grant-tables &

Login with root:

mysql -uroot

And assign the DB that needs to be used:

use mysql;

Now all you have to do is reset your root password of the MySQL user and restart the MySQL service:

update user set password=PASSWORD("YOURPASSWORDHERE") where User='root';
flush privileges;

quit and restart MySQL:

quit
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

Now your root password should be working with the one you just set, check it with:

mysql -u root -p

Hope this will help you figure it out.

Which one-click-setup did you use? You can check the configuration files probably and find the password. If you can’t find it, neither root without pass is working you can reset it:

Commands

sudo /etc/init.d/mysql stop

Now start up MySQL in safe mode, so you’ll skip the privileges table:

sudo mysqld_safe --skip-grant-tables &

Login with root:

mysql -uroot

And assign the DB that needs to be used:

use mysql;

Now all you have to do is reset your root password of the MySQL user and restart the MySQL service:

update user set password=PASSWORD("YOURPASSWORDHERE") where User='root';
flush privileges;

quit and restart MySQL:

quit
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

Now your root password should be working with the one you just set, check it with:

mysql -u root -p

Hope this will help you figure it out.

Which one-click-setup did you use? You can check the configuration files probably and find the password. If you can’t find it, neither root without pass is working you can reset it:

Commands

sudo /etc/init.d/mysql stop

Now start up MySQL in safe mode, so you’ll skip the privileges table:

sudo mysqld_safe --skip-grant-tables &

Login with root:

mysql -uroot

And assign the DB that needs to be used:

use mysql;

Now all you have to do is reset your root password of the MySQL user and restart the MySQL service:

update user set password=PASSWORD("YOURPASSWORDHERE") where User='root';
flush privileges;

quit and restart MySQL:

quit
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

Now your root password should be working with the one you just set, check it with:

mysql -u root -p

Hope this will help you figure it out.

Which one-click-setup did you use? You can check the configuration files probably and find the password. If you can’t find it, neither root without pass is working you can reset it:

Commands

sudo /etc/init.d/mysql stop

Now start up MySQL in safe mode, so you’ll skip the privileges table:

sudo mysqld_safe --skip-grant-tables &

Login with root:

mysql -uroot

And assign the DB that needs to be used:

use mysql;

Now all you have to do is reset your root password of the MySQL user and restart the MySQL service:

update user set password=PASSWORD("YOURPASSWORDHERE") where User='root';
flush privileges;

quit and restart MySQL:

quit
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

Now your root password should be working with the one you just set, check it with:

mysql -u root -p

Hope this will help you figure it out.

I am also new in DigitalOcean and was following this article to setup a LEMP server: https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-on-ubuntu-20-04

I was having trouble on the last step. I was unable to connect to the database using the php script. It was showing the following error:

“Error!: SQLSTATE[HY000] [1045] Access denied for user”

I was able to log-in from the terminal using the same credential and was able to see the records on the table, but the php script was showing the connection error for the same credential, which was weird!

After searching all the posts on stackoverflow, found no solution for this. Finally don’t know why, I ran the php file from the terminal like this instead of the browser:

‘php /var/www/yourdomain/todolist.php’

which was showing me an error on line 3, which was the line with the password. It was telling me something like an empty value and indicating the last 2 characters of the password. I then noticed that in my password, before these last two characters, I have a “$” sign, which is the reserved symbol in php to indicate a variable!

So I changed my mysql user password with the following command:

“ALTER USER 'userName’@'localhost’ IDENTIFIED BY 'New-Password-Here’;”

And updated the php script accordingly. Voila! All worked perfectly afterwards!

Lesson learned: Do not have “$” sign on your password.

Hope it will save others an hour of tension on my same situation!