I connect to a remote MySQL server (on the default port 3306) using the mysql_real_connect() C API call.
mysql_real_connect()
How to find out which TCP port is used on the client host?
Can I specify the port that I want to use?
You can use lsof . Enter the following in the shell:
lsof
$ lsof | grep TCP
And then find the port on which your mysql server is listening.
You can also use netstat . Details can be found on man netstat .
netstat
man netstat
As far as I know, you cannot.