如何测试MySQL在哪个端口上运行以及是否可以连接到该端口?

如何测试MySQL在哪个端口上运行以及是否可以连接到该端口?

问题描述:

我已经安装了MySQL,甚至以用户身份登录那里.

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 :)

如何确定端口确实是3306?是否有Linux命令以某种方式查看它? 另外,还有没有更正确的方法可以通过网址进行尝试?

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?

要在端口上查找侦听器,请执行以下操作:

To find a listener on a port, do this:

netstat -tln

如果mysql确实在该端口上侦听,您应该会看到这样的一行.

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      

端口3306是MySql的默认端口.

Port 3306 is MySql's default port.

要进行连接,您只需使用所需的任何客户端,例如基本的mysql客户端.

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

mysql -h localhost -u用户数据库

mysql -h localhost -u user database

或由您的库代码解释的网址.

Or a url that is interpreted by your library code.