MySQL – ERROR 1045 (28000): Access denied for user

Everybody knows Mysql. Normally it “just works”. But a few days ago I tried to connect to a mysql server with the mysql command line client and got this error.

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

Funny thing: If you want to use the mysql command client to connect with the mysql server, you can do something like this

mysql -u root -pPassword

Where does it try to connect itself? To localhost and the well known port 3306? Wrong. It tries to access the mysql socket file. Which in my case, was not existing (because I had mysql in a docker container). I just wanted to connect via IP address and port.

Next try: Access the server via host parameter

mysql -u root-pPassword -h127.0.0.1

But: Same error! If the mysql client sees the ip address, it tries the socket file again! You have to explicitly tell the mysql client to use TCP to connect.

mysql -u root-pPassword -h127.0.0.1 –protocol=tcp

(Thanks to stackexchange for this information!)


Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: