105

This is what I'm doing:

mysql --host=localhost --port=9999 mysql -u root -p --execute="show tables;"

The command works (connecting to port 3306) no matter what I provide in --port argument. I have two mysql servers running on one machine, and want to connect to the second one by explicitly providing its port number. What's going on? Why does mysql ignore this parameter?

185

When localhost parameter given, MySQL uses sockets. Use 127.0.0.1 instead.

| improve this answer | |
  • 18
    Quite infuriating that this fact isn't mentioned on the mysql man page. – Janek Nov 15 '16 at 15:56
  • 1
    Besides accepted answer here, a bit more explanation can be found in this mysql bugreport and also link to man page. As one of commenters in bugreport page, I also don't understand why doesn't client at least throw a warning in case of using 'localhost' in connection string. – bukva-ziu Mar 26 '17 at 8:51
  • 3
    You're a life saver man! – Touqeer Shafi Oct 17 '17 at 11:56
  • i'm using mysql for a decade now, but this did not crossed my way, yet ... – pscheit Dec 26 '17 at 20:25
  • 2
    Wow, unbelievable that this insane bug is still present 10 years later.. I guess that says a lot about Oracle as well as MariaDb teams. To be clear: the client actually takes the port command, it complains if the port is wrong but it ignores it and connects by socket instead. I started debugging the binary when I found this answer. – John Dec 20 '19 at 4:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.