Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to connect to mysql at 127.0.0.1:3306 with user root access denied for user 'root'@'localhost'(using password:YES)

I've been trying to create a new database connection on workbench. However, every time I test a connection there is an error message that says

Failed to connect to mysql at 127.0.0.1:3306 with user root access denied for user 'root'@'localhost'(using password:YES)

I don't know what's the cause of this error. I have tried uninstalling and re-installing my workbench 6.1 and mysql server 5.6 but the error is still unsolved.

like image 843
cpl Avatar asked Sep 11 '14 02:09

cpl


People also ask

How do I fix MySQL error Access denied for user root localhost?

Use the ALTER USER command and change the authentication method to log into MySQL as root: ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'insert_password'; This command changes the password for the user root and sets the authentication method to mysql_native_password.

How do I fix MySQL access denied error?

To resolve the error, you must create a user with the following command: mysql> GRANT ALL ON *. * to user_name@localhost IDENTIFIED BY 'password'; Replace user_name with the user's username and password with the user's password.

Can not connect MySQL server on localhost 3306?

normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.


2 Answers

First check if it's a workbench or connection problem.

1) In your windows run 'cmd' to open a terminal

Try both

2a) mysql -u root -p -h 127.0.0.1 -P 3306

2b) mysql -u root -p -h > localhost -P 3306

3) If the connection is good you will get a password prompt, see if you can connect with correct password.

If your connection is denied, just grant the permission

mysql >GRANT ALL ON [DatabaseName].* TO 'root'@'127.0.0.1' IDENTIFIED BY '[PASSWORD]'; 

If your connection is accepted here, it's like a workbench configuration problem.

like image 147
ydoow Avatar answered Sep 20 '22 08:09

ydoow


I had the same problem.
I've installed fresh mysql at Ubuntu but I left mysql password empty, and as a result I couldn't connect to mysql in any way.
Lately I've revealed that there is a table of users where are names, hosts, passwords and some plugins. So for my user root@localhost mysql while installing assigned a plugin called auth_socket, which let Unix user "root" log in as a mysql user "root" without password, but don't allow login as another Unix user. So to fix that you should turn off this plugin and set usual authentication:

  1. open Linux terminal
  2. enter "sudo mysql"
    you will see "mysql >" which means you've connected to mysql as a 'root' Unix user and you can type SQL queries.
  3. enter SQL query to change a way how you will log in:
    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_new_password';
    where 'mysql_native_password' means - to turn off auth_socket plugin.
like image 24
Vladimir Voznyi Avatar answered Sep 23 '22 08:09

Vladimir Voznyi