Mysql – Why is the thesql client utility not using the port I specify

mac-osxMySQLport

I'm trying to use mysql (command line utility) to connect to MySQL server through SSH tunnel.
The problem is this MySQL client won't use my specified port.
For example, I ran this:

$ mysql -uroot --port=1234

And it then just connected to port 3306.

Why does it do that?

How can I force this client to connect to port 1234 (then it should show me that port 1234 is not connectable).

Best Answer

If you are running the mysql client on the same host that the server is running, it is probably making a socket connection, and not using the port at all. Try adding --protocol=TCP to your command

mysql -uroot --protocol=TCP --port=1234