如何更改mysql/mariadb 10.xx默认端口?

如何更改mysql/mariadb 10.xx默认端口?,mysql,linux,mariadb,Mysql,Linux,Mariadb,准确地说,我需要将mysql/mariadb 10.xx默认端口更改为端口号15501 通过互联网,我发现它可以从/etc/mysql/my.cnf更改为包含一行port=3306,但在我的cnf文件中没有这样的行 我的My.cnf目录: # The MariaDB configuration file # # The MariaDB/MySQL tools read configuration files in the following order: # 1. "/etc/mysql/

准确地说,我需要将mysql/mariadb 10.xx默认端口更改为端口号15501

通过互联网,我发现它可以从
/etc/mysql/my.cnf
更改为包含一行
port=3306
,但在我的cnf文件中没有这样的行

我的
My.cnf
目录:

# The MariaDB configuration file
 #
 # The MariaDB/MySQL tools read configuration files in the following order:
 # 1. "/etc/mysql/mariadb.cnf" (this file) to set global defaults,
 # 2. "/etc/mysql/conf.d/*.cnf" to set global options.
 # 3. "/etc/mysql/mariadb.conf.d/*.cnf" to set MariaDB-only options.
 # 4. "~/.my.cnf" to set user-specific options.
 #
 # If the same option is defined multiple times, the last one will apply.
 #
 # One can use all long options that the program supports.
 # Run program with --help to get a list of available options and with
 # --print-defaults to see which it would actually understand and use.

 #
 # This group is read both both by the client and the server
 # use it for options that affect everything
 #
 [client-server]

 # Import all .cnf files from configuration directory
 !includedir /etc/mysql/conf.d/
 !includedir /etc/mysql/mariadb.conf.d/
不知道为什么,但如果我尝试
mysql-uroot-p-p[任何_端口都是可接受的示例1829]
它用任何端口号连接到mariadb

netstat -a | grep mysql
tcp        0      0 localhost:mysql         0.0.0.0:*               LISTEN     
unix  2      [ ACC ]     STREAM     LISTENING     17787    /var/run/mysqld  /mysqld.sock

mysql --version
mysql  Ver 15.1 Distrib 10.1.23-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2
我用的是Debian9


如果您能告诉我如何使mysql/mariadb仅侦听端口15501号,我将不胜感激。

mysql命令使用套接字文件连接到本地mariadb服务器。您可以使用netstat查看哪个端口为mysql连接打开:

netstat -tulpen | grep mysql
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      104        1511        954/mysqld
例如,您可以在配置文件中搜索默认端口,并将此行的端口更改为15501:

$ find /etc/mysql/ -name "*.cnf" -exec grep -nHR '3306' {} \;
/etc/mysql/my.cnf:20:port               = 3306
/etc/mysql/my.cnf:38:port               = 3306

mysql命令使用套接字文件连接到本地mariadb服务器。您可以使用netstat查看哪个端口为mysql连接打开:

netstat -tulpen | grep mysql
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      104        1511        954/mysqld
例如,您可以在配置文件中搜索默认端口,并将此行的端口更改为15501:

$ find /etc/mysql/ -name "*.cnf" -exec grep -nHR '3306' {} \;
/etc/mysql/my.cnf:20:port               = 3306
/etc/mysql/my.cnf:38:port               = 3306

第一个问题的答案(您想在不同的端口上运行mariadb)是:在
my.cnf
mysqld
部分下添加一个端口行,例如:

[mysqld]
port=15501
然后重新启动服务。这会让你的mariadb收听15501而不是3306


关于第二部分。。。我猜您没有指定主机名,因此在/var/lib/mysql/mysql.sock中默认为localhost和localsocket connection,忽略您提供的端口参数,因为local socket不使用端口。

第一个问题的答案(您想在不同的端口上运行mariadb)is:在
mysqld
部分下的
my.cnf
中添加端口行,例如:

[mysqld]
port=15501
然后重新启动服务。这会让你的mariadb收听15501而不是3306


关于第二部分。。。我猜您没有指定主机名,所以它默认为/var/lib/mysql/mysql.sock中的localhost和local socket connection,忽略您提供的端口参数,因为local socket不使用端口。

在配置文件的第4到第7行中列出了“MariaDB/mysql工具读取配置文件”的位置。你看。其中一个将包含端口。在配置文件的第4到第7行中,列出了“MariaDB/MySQL工具读取配置文件”的位置。你看。其中一个将包含端口。@apansiv好的,首先我很抱歉我的回复太晚了,无论如何我在
/etc/mysql/mariadb.conf.d/50 server.cnf中找到了
port=3306
,它仍然会打开与任何服务器的连接port@apansiv好的,首先我很抱歉我迟了回复,无论如何,我在
/etc/mysql/mariadb.conf.d/50 server.cnf中找到了
port=3306
,它仍然会打开与任何端口的连接