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?


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

  • 14
    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

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.