GeekedOut GeekedOut - 7 months ago 13
SQL Question

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

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

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      

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.