MySQL远程连接超时和3306端口关闭

MySQL远程连接超时和3306端口关闭

我一直在寻找解决办法但没有任何效果。

我正在尝试允许远程访问我的 MySQL 数据库。

我一直在编辑我的/etc/mysql/mysql.conf.d/mysqld.cnf以修改绑定地址以将其设置为0.0.0.0,并启用端口 3306 以允许每台机器。

ufw 状态

OpenSSH                    ALLOW       Anywhere
Apache Full                ALLOW       Anywhere
Apache                     ALLOW       Anywhere
Postfix                    ALLOW       Anywhere
Dovecot IMAP               ALLOW       Anywhere
Dovecot POP3               ALLOW       Anywhere
Dovecot Secure POP3        ALLOW       Anywhere
Dovecot Secure IMAP        ALLOW       Anywhere
3306/tcp                   ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)
Apache Full (v6)           ALLOW       Anywhere (v6)
Postfix (v6)               ALLOW       Anywhere (v6)
Dovecot IMAP (v6)          ALLOW       Anywhere (v6)
Dovecot POP3 (v6)          ALLOW       Anywhere (v6)
Dovecot Secure POP3 (v6)   ALLOW       Anywhere (v6)
Dovecot Secure IMAP (v6)   ALLOW       Anywhere (v6)
3306/tcp (v6)              ALLOW       Anywhere (v6)

但是当我查看我的端口 3306 是否打开时,它告诉我它已关闭(nmap也没有发现它是开放的和在线的服务)

我已经尝试删除绑定地址而不是修改它,同样的问题 :/

在这个阶段,我不知道可能出了什么问题,我已经用 iptable 设置了一条规则

iptables -A INPUT -i enp1s0 -p tcp --destination-port 3306 -j ACCEPT

即使这样也不起作用。

也许它可以有所帮助,但是在我的 mysql conf 文件中,我已经将mysqlx-bind-address其设置为0.0.0.0.0并且也尝试删除它,但没有用。

我一直在寻找跳过网络,但它似乎在我的 mysql 配置中缺失。

在这个阶段,我很困惑我应该怎么做才能打开我的 3306 端口并能够远程访问我的 MySQL 数据库

这是 mysql 配置:

#
# The MySQL database server configuration file.
#
# 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.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

# Here is entries for some specific programs
# The following values assume you have at least 32M ram

[mysqld]
#
# * Basic Settings
#
user        = mysql
# pid-file  = /var/run/mysqld/mysqld.pid
# socket    = /var/run/mysqld/mysqld.sock
#port       = 3306
# datadir   = /var/lib/mysql


# If MySQL is running as a replication slave, this should be
# changed. Ref https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_tmpdir
# tmpdir        = /tmp
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 0.0.0.0
#mysqlx-bind-address    = 0.0.0.0
#
# * Fine Tuning
#
key_buffer_size     = 16M
# max_allowed_packet    = 64M
# thread_stack      = 256K

# thread_cache_size       = -1

# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options  = BACKUP

# max_connections        = 151

# table_open_cache       = 4000

#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
#
# Log all queries
# Be aware that this log type is a performance killer.
# general_log_file        = /var/log/mysql/query.log
# general_log             = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
# slow_query_log        = 1
# slow_query_log_file   = /var/log/mysql/mysql-slow.log
# long_query_time = 2
# log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
#       other settings you may need to change.
# server-id     = 1
# log_bin           = /var/log/mysql/mysql-bin.log
# binlog_expire_logs_seconds    = 2592000
max_binlog_size   = 100M
# binlog_do_db      = include_database_name
# binlog_ignore_db  = include_database_name

# Prestashop special conf
read_buffer_size            = 2M 
read_rnd_buffer_size        = 1M
join_buffer_size            = 2M 
sort_buffer_size            = 2M
innodb_buffer_pool_size     = 1G

我在使用数字海洋 VPS,如果这能有帮助的话。

顺便说一句,我的日志中没有任何错误,我的网站仍然运行良好。

更多信息 :

我已经重现:https://www.digitalocean.com/community/tutorials/how-to-allow-remote-access-to-mysql在第二个 vps 上,使用相同的 mysql、php 和 apache 配置,并且它可以正常工作,我联系了 Digital Ocean 支持团队,因为我不明白为什么在重现我在第二个 vps 上所做的相同操作后,我的端口 3306 仍然被阻止。

这是我的netstat -plant | grep 3306

tcp6       0      0 :::33060                :::*                    LISTEN      33071/mysqld
tcp6       0      0 :::3306                 :::*                    LISTEN      33071/mysqld

相关内容