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

GeekedOut picture GeekedOut · May 3, 2011 · Viewed 442.4k times · Source

I have installed MySQL and even logged in there as a user.

But when I try to connect like this:

http://localhost:3306
mysql://localhost:3306

Neither works. Not sure if both are supposed to work, but at least one of them should :)

How can I make sure that the port is indeed 3306? Is there a linux command to see it somehow? Also, is there a more correct way to try it via a url?

Answer

Keith picture Keith · May 3, 2011

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.