Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 connectible).

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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

share|improve this answer

If you use TCP/IP you should specify the host IP. If the host is localhost, you must use 127.0.0.1 instead.

In other words

mysql -uroot -h127.0.0.1 -P1234 -p (if the root has a password)

mysql -uroot -h127.0.0.1 -P1234 (if the root does not has a password)

Once logged in, run this query to make sure:

SHOW VARIABLES LIKE 'port';

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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