mysql默认端口号
MySQL is very popular database in the opensource community. While developing applications or connecting MySQL database we need to specify the MySQL port implicitly or explicitly. In this tutorial we will learn MySQL default port number and alternative port numbers.
MySQL是开源社区中非常流行的数据库。 在开发应用程序或连接MySQL数据库时,我们需要隐式或显式指定MySQL端口。 在本教程中,我们将学习MySQL默认端口号和备用端口号。
TCP 3306 (TCP 3306)
The default port for the MySQL service is TCP 3306. This port can be also used for MariaDB database server.
MySQL服务的默认端口是TCP3306。该端口也可用于MariaDB数据库服务器。
使用netstat命令列出 (List with netstat Command)
We can use netstat
command in order to list MySQL/MariaDB database server port number.
我们可以使用netstat
命令来列出MySQL / MariaDB数据库服务器端口号。
$ sudo netstat -p -l -n | grep mysql
We can see from output that port 3306
port is listening on the local interface 127.0.0.1
从输出中我们可以看到端口3306
端口正在本地接口127.0.0.1
上侦听
For MariaDB change grep mysql
with grep mariadb
对于MariaDB,使用grep mariadb
更改grep mysql
从数据库配置文件查找 (Find From DB Config File)
What if MySQL server default port is different from 3306
. We have some options. One of them is looking to the application database config file. We can get the port number from there. In this example the port number 3307
is specified explicitly.
如果MySQL服务器的默认端口与3306
不同,该怎么办。 我们有一些选择。 其中之一是寻找应用程序数据库配置文件。 我们可以从那里获取端口号。 在此示例中,端口号3307
被明确指定。
$link = mysql_connect('poftut.com:3307', 'mysql_user', 'mysql_password');
通过Nmap扫描查找 (Find By Nmap Scan)
If we had no clue about the port number we can use some security network scanning tool named nmap
. We can scan popular or all port on the host and find MySQL service. Following command will scan top used 1000 ports.
如果我们不知道端口号,可以使用一些名为nmap
安全网络扫描工具。 我们可以扫描主机上的常用端口或所有端口,然后找到MySQL服务。 以下命令将扫描使用最多的1000个端口。
$ nmap -sC -sV 192.168.1.10
OR we can scan all ports of the given host.
或者我们可以扫描给定主机的所有端口。
$ nmap -p- -sC -sV 192.168.1.10
使用SQL查询查找 (Find with SQL Query)
Configuration parameter of the MySQL or MariaDB Database server is stored in the variables too. We can use some SQL inorder to print the port information from environment variables like below.
MySQL或MariaDB数据库服务器的配置参数也存储在变量中。 我们可以使用一些SQL命令来从以下环境变量中打印端口信息。
SHOW VARIABLES WHERE Variable_name = 'port';
We can see that port
variable is current set to 3306
.
我们可以看到port
变量当前设置为3306
。
mysql默认端口号