如何测试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 命令以某种方式查看它?另外,有没有更正确的方法来通过 url 尝试它?

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

或由您的库代码解释的 url.

Or a url that is interpreted by your library code.