mysql默认端口号_什么是MySQL默认端口号?

mysql默认端口号

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
List with netstat Command
List with netstat Command
使用netstat命令列出

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';
Find with SQL Query
Find with SQL Query
使用SQL查询查找

We can see that port variable is current set to  3306.

我们可以看到port变量当前设置为3306

LEARN MORE  How to Install Mariadb / Mysql Server in Linux Fedora, CentOS and RedHat?
了解更多如何在Linux Fedora,CentOS和RedHat中安装Mariadb / Mysql Server?

翻译自: https://www.poftut.com/mysql-default-port-number/

mysql默认端口号

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值