How to check what port mysql is running on

Solution 1:

I did

mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';

And that indicated that I was using port 3306 and that my search for the error continues.

Solution 2:

The best way to actually know what application is listening to which interface and on what port is to use netstat

You can do this as root:

netstat -tlnp

It will list out all the listening services like this:

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      25934/mysqld
tcp6       0      0 :::22                   :::*                    LISTEN      7964/dropbear

The last column shows you that mysqld bound itself to port 3306 listening on all interfaces.

In fact, this works for everything, not just mysql. You can also use it non TCP sockets.

Solution 3:

Enter via terminal to mysql:

mysql -u root

and then type the following in the mysql prompt:

mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';

This worked for me.

Solution 4:

If you really want to confirm that it is running on the port you can telnet into the port while the process is up like so:

telnet localhost 3306

You'll see it report that you're connected to mySQL.

Alernatively, you can find the process's PID using ps and grep:

ps -ef | grep mysql

and then put that pid into lsof to print out all the open file descriptors. You'll find the port the process is bound to near the top.