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 127.0.0.1, 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