【问题标题】:how to change mysql/mariadb 10.xx default port?如何更改 mysql/mariadb 10.xx 默认端口?
【发布时间】:2017-07-21 12:40:58
【问题描述】:

确切地说,我需要将 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[ANY_PORT IS ACCEPTED example 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

我正在使用 debian 9

如果你能告诉我如何让 mysql/mariadb 只监听 15501 端口号,我将不胜感激。

【问题讨论】:

  • 配置文件的第 4 到第 7 行是“MariaDB/MySQL 工具读取配置文件”的位置列表。所以看那里。其中之一将包含端口。

标签: mysql linux mariadb


【解决方案1】:

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

[mysqld]
port=15501

然后重新启动您的服务。这应该让你的 mariadb 监听 15501 而不是 3306。

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

【讨论】:

    【解决方案2】:

    mysql-command 正在使用套接字文件连接到本地 mariadb-server。您可以使用 netstat 查看为 mysql-connections 打开的端口:

    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
    

    【讨论】:

    • @apansiv 好的,首先我很抱歉我的回复迟了,无论如何我确实在/etc/mysql/mariadb.conf.d/50-server.cnf 找到了port = 3306 它仍然可以打开与任何端口的连接
    猜你喜欢
    • 1970-01-01
    • 2015-05-24
    • 2016-11-02
    • 2011-10-19
    • 1970-01-01
    • 1970-01-01
    • 2019-09-08
    • 2021-09-03
    • 1970-01-01
    相关资源
    最近更新 更多