How to test which port MySQL is running on and whether it can be connected to? How to test which port MySQL is running on and whether it can be connected to? linux linux

How to test which port MySQL is running on and whether it can be connected to?


To find a listener on a port, do this:

netstat -tln

You should see a line that looks like this if mysql is indeed listening on that port.

tcp        0      0 127.0.0.1:3306              0.0.0.0:*                   LISTEN      

Port 3306 is MySql's default port.

To connect, you just have to use whatever client you require, such as the basic mysql client.

mysql -h localhost -u user database

Or a url that is interpreted by your library code.


Using Mysql client:

mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';


grep port /etc/mysql/my.cnf ( at least in debian/ubuntu works )

or

netstat -tlpn | grep mysql

verify

bind-address 127.0.0.1

in /etc/mysql/my.cnf to see possible restrictions