How to get the port of a connection in mysql
You should be able to use one of the solutions in this StackOverflow: How do I find out my MySQL URL, host, port and username?
Specifically I think this is what you're looking for: SHOW VARIABLES WHERE Variable_name = 'port';