无法连接到远程 MySQL(v. 8.0.33 | ubuntu 22.04.2)

无法连接到远程 MySQL(v. 8.0.33 | ubuntu 22.04.2)

在操作系统为ubuntu 22.04.2的服务器上安装了MySQL版本8.0.33,配置如下:

/etc/mysql/mysql.conf.d/mysqld.cnf

#
# 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_tmpd>
# 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
log_error_verbosity = 3
#
# 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
#

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2023-06-28 22:25:07 +03; 6min ago
    Process: 2043942 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
   Main PID: 2043950 (mysqld)
     Status: "Server is operational"
      Tasks: 37 (limit: 77022)
     Memory: 369.5M
        CPU: 1.782s
     CGroup: /system.slice/mysql.service
             └─2043950 /usr/sbin/mysqld

journalctl -xeu mysql.service

░░ The job identifier is 40379 and the job result is done.
чэр 28 22:31:19 riven systemd[1]: mysql.service: Consumed 1.865s CPU time.
░░ 
░░ The unit mysql.service completed and consumed the indicated resources.
чэр 28 22:31:20 riven systemd[1]: Started MySQL Community Server.
░░ Subject: A start job for unit mysql.service has finished successfully
░░ Defined-By: systemd
░░ Support: http://www.ubuntu.com/support
░░ 
░░ A start job for unit mysql.service has finished successfully.
░░ 
░░ The job identifier is 40379.

如您所见,MySQL 运行良好,我可以在本地连接到数据库。

同时防火墙开放3306端口:

ufw 状态

Status: active

To                         Action      From
--                         ------      ----
7346                       ALLOW       Anywhere                  
20                         DENY        Anywhere                  
21                         DENY        Anywhere                  
40000:50000/tcp            ALLOW       Anywhere                  
63940/tcp                  ALLOW       Anywhere                  
22                         DENY        Anywhere                  
62390/tcp                  ALLOW       Anywhere                  
3306                       ALLOW       Anywhere                  
7346 (v6)                  ALLOW       Anywhere (v6)             
20 (v6)                    DENY        Anywhere (v6)             
5438 (v6)                  DENY        Anywhere (v6)             
40000:50000/tcp (v6)       ALLOW       Anywhere (v6)             
63940/tcp (v6)             ALLOW       Anywhere (v6)             
21 (v6)                    DENY        Anywhere (v6)             
22 (v6)                    DENY        Anywhere (v6)             
62390/tcp (v6)             ALLOW       Anywhere (v6)             
3306 (v6)                  ALLOW       Anywhere (v6)             

在 MikroTIK 路由器的防火墙中,该端口也处于打开状态,在站点上检查该端口时,系统检测到该端口已打开:

端口检查器

netstat -plant | grep 3306

tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      1352891/mysqld      
tcp        0      0 0.0.0.0:33060           0.0.0.0:*               LISTEN      1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:58800         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:55746         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:33418         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:39848         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:46750         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:59064         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:51772         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:54564         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:52302         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:35614         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:37432         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:60826         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:33426         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:42130         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:41456         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:41460         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:36806         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:35598         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:34444         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:38860         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:36408         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:35390         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:51960         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:43738         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:41452         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:54074         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:41412         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:34454         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:51952         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:40964         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:45992         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:35824         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:40960         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:41428         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:55762         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:50532         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:58294         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:34820         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:59480         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:57184         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:36818         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:43718         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:56458         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:33416         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:33284         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:43732         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:38978         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:57180         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:55758         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:60552         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:54072         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:44856         127.0.0.1:3306          ESTABLISHED 368580/Code --stand 
tcp        0      0 127.0.0.1:3306          127.0.0.1:33412         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:57182         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:42242         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:35774         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:35184         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:38870         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:60834         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:60844         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:38858         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:46758         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:40978         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:50702         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:35824         127.0.0.1:3306          ESTABLISHED 368580/Code --stand 
tcp        0      0 127.0.0.1:3306          127.0.0.1:55730         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:33112         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:36820         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:38874         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:52296         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:38420         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:38770         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:40164         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:45996         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:36790         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:49712         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:41442         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:44856         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:38880         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:34834         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:41430         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:60818         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:38984         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:50706         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:35630         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:41618         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:51780         ESTABLISHED 1352891/mysqld      
tcp        0      0 127.0.0.1:3306          127.0.0.1:40974         ESTABLISHED 1352891/mysqld      
tcp6       0      0 127.0.0.1:46750         127.0.0.1:3306          ESTABLISHED 883/java            
tcp6       0      0 127.0.0.1:34444         127.0.0.1:3306          ESTABLISHED 883/java            
tcp6       0      0 127.0.0.1:38870         127.0.0.1:3306          ESTABLISHED 829/java            
tcp6       0      0 127.0.0.1:55758         127.0.0.1:3306          ESTABLISHED 819/java            
tcp6       0      0 127.0.0.1:38874         127.0.0.1:3306          ESTABLISHED 819/java            
tcp6       0      0 127.0.0.1:51960         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:33416         127.0.0.1:3306          ESTABLISHED 825/java            
tcp6       0      0 127.0.0.1:42130         127.0.0.1:3306          ESTABLISHED 883/java            
tcp6       0      0 127.0.0.1:57180         127.0.0.1:3306          ESTABLISHED 829/java            
tcp6       0      0 127.0.0.1:49712         127.0.0.1:3306          ESTABLISHED 883/java            
tcp6       0      0 127.0.0.1:57182         127.0.0.1:3306          ESTABLISHED 829/java            
tcp6       0      0 127.0.0.1:59064         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:33418         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:38770         127.0.0.1:3306          ESTABLISHED 1997254/java        
tcp6       0      0 127.0.0.1:35614         127.0.0.1:3306          ESTABLISHED 847/java            
tcp6       0      0 127.0.0.1:41430         127.0.0.1:3306          ESTABLISHED 819/java            
tcp6       0      0 127.0.0.1:38858         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:35184         127.0.0.1:3306          ESTABLISHED 847/java            
tcp6       0      0 127.0.0.1:50702         127.0.0.1:3306          ESTABLISHED 847/java            
tcp6       0      0 127.0.0.1:34454         127.0.0.1:3306          ESTABLISHED 829/java            
tcp6       0      0 127.0.0.1:54564         127.0.0.1:3306          ESTABLISHED 1997254/java        
tcp6       0      0 127.0.0.1:50706         127.0.0.1:3306          ESTABLISHED 883/java            
tcp6       0      0 127.0.0.1:40964         127.0.0.1:3306          ESTABLISHED 825/java            
tcp6       0      0 127.0.0.1:41456         127.0.0.1:3306          ESTABLISHED 883/java            
tcp6       0      0 127.0.0.1:50532         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:60834         127.0.0.1:3306          ESTABLISHED 819/java            
tcp6       0      0 127.0.0.1:39848         127.0.0.1:3306          ESTABLISHED 883/java            
tcp6       0      0 127.0.0.1:40960         127.0.0.1:3306          ESTABLISHED 883/java            
tcp6       0      0 127.0.0.1:52296         127.0.0.1:3306          ESTABLISHED 847/java            
tcp6       0      0 127.0.0.1:51772         127.0.0.1:3306          ESTABLISHED 883/java            
tcp6       0      0 127.0.0.1:41460         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:36818         127.0.0.1:3306          ESTABLISHED 819/java            
tcp6       0      0 127.0.0.1:35598         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:41428         127.0.0.1:3306          ESTABLISHED 847/java            
tcp6       0      0 127.0.0.1:34834         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:33112         127.0.0.1:3306          ESTABLISHED 825/java            
tcp6       0      0 127.0.0.1:46758         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:40974         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:40978         127.0.0.1:3306          ESTABLISHED 847/java            
tcp6       0      0 127.0.0.1:41452         127.0.0.1:3306          ESTABLISHED 819/java            
tcp6       0      0 127.0.0.1:40164         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:51780         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:51952         127.0.0.1:3306          ESTABLISHED 825/java            
tcp6       0      0 127.0.0.1:35390         127.0.0.1:3306          ESTABLISHED 825/java            
tcp6       0      0 127.0.0.1:60818         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:55762         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:60552         127.0.0.1:3306          ESTABLISHED 1997254/java        
tcp6       0      0 127.0.0.1:45992         127.0.0.1:3306          ESTABLISHED 1997254/java        
tcp6       0      0 127.0.0.1:60826         127.0.0.1:3306          ESTABLISHED 825/java            
tcp6       0      0 127.0.0.1:38880         127.0.0.1:3306          ESTABLISHED 829/java            
tcp6       0      0 127.0.0.1:36790         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:38420         127.0.0.1:3306          ESTABLISHED 1997254/java        
tcp6       0      0 127.0.0.1:33284         127.0.0.1:3306          ESTABLISHED 825/java            
tcp6       0      0 127.0.0.1:33412         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:43738         127.0.0.1:3306          ESTABLISHED 883/java            
tcp6       0      0 127.0.0.1:36806         127.0.0.1:3306          ESTABLISHED 829/java            
tcp6       0      0 127.0.0.1:43732         127.0.0.1:3306          ESTABLISHED 819/java            
tcp6       0      0 127.0.0.1:56458         127.0.0.1:3306          ESTABLISHED 825/java            
tcp6       0      0 127.0.0.1:45996         127.0.0.1:3306          ESTABLISHED 1997254/java        
tcp6       0      0 127.0.0.1:43718         127.0.0.1:3306          ESTABLISHED 847/java            
tcp6       0      0 127.0.0.1:58294         127.0.0.1:3306          ESTABLISHED 825/java            
tcp6       0      0 127.0.0.1:54074         127.0.0.1:3306          ESTABLISHED 1997254/java        
tcp6       0      0 127.0.0.1:35630         127.0.0.1:3306          ESTABLISHED 829/java            
tcp6       0      0 127.0.0.1:41412         127.0.0.1:3306          ESTABLISHED 825/java            
tcp6       0      0 127.0.0.1:59480         127.0.0.1:3306          ESTABLISHED 847/java            
tcp6       0      0 127.0.0.1:41442         127.0.0.1:3306          ESTABLISHED 819/java            
tcp6       0      0 127.0.0.1:34820         127.0.0.1:3306          ESTABLISHED 847/java            
tcp6       0      0 127.0.0.1:42242         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:52302         127.0.0.1:3306          ESTABLISHED 825/java            
tcp6       0      0 127.0.0.1:36820         127.0.0.1:3306          ESTABLISHED 819/java            
tcp6       0      0 127.0.0.1:55730         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:35774         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:37432         127.0.0.1:3306          ESTABLISHED 829/java            
tcp6       0      0 127.0.0.1:58800         127.0.0.1:3306          ESTABLISHED 1997254/java        
tcp6       0      0 127.0.0.1:60844         127.0.0.1:3306          ESTABLISHED 829/java            
tcp6       0      0 127.0.0.1:57184         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:33426         127.0.0.1:3306          ESTABLISHED 829/java            
tcp6       0      0 127.0.0.1:38978         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:36408         127.0.0.1:3306          ESTABLISHED 1997254/java        
tcp6       0      0 127.0.0.1:38984         127.0.0.1:3306          ESTABLISHED 800/java            
tcp6       0      0 127.0.0.1:38860         127.0.0.1:3306          ESTABLISHED 825/java            
tcp6       0      0 127.0.0.1:54072         127.0.0.1:3306          ESTABLISHED 1997254/java        
tcp6       0      0 127.0.0.1:55746         127.0.0.1:3306          ESTABLISHED 847/java            
tcp6       0      0 127.0.0.1:41618         127.0.0.1:3306          ESTABLISHED 819/java    

但是,尝试使用 DataGrip 连接数据库时出现错误:

[08S01] 通信链路故障 最后一个成功发送到服务器的数据包是在 0 毫秒前。驱动程序尚未收到来自服务器的任何数据包。

日志中的更多详细信息:

想法日志

2023-06-26 22:34:52,336 [262405502]   INFO - ution.rmi.RemoteProcessSupport - /Applications/DataGrip.app/Contents/jbr/Contents/Home/bin/java -Djava.rmi.server.hostname=127.0.0.1 -Duser.timezone=UTC -Xmx2048m -Xms128m -Dfile.encoding=UTF-8 -classpath "/Applications/DataGrip.app/Contents/lib/util.jar:/Applications/DataGrip.app/Contents/lib/groovy-2.5.14.jar:/Applications/DataGrip.app/Contents/plugins/DatabaseTools/lib/jdbc-console.jar:/Users/riven/Library/Application Support/JetBrains/DataGrip2021.2/jdbc-drivers/MySQL ConnectorJ/8.0.25/mysql-connector-java-8.0.25.jar" com.intellij.database.remote.RemoteJdbcServer com.mysql.cj.jdbc.Driver 
2023-06-26 22:34:52,538 [262405704]   INFO - ution.rmi.RemoteProcessSupport - Port/ServicesPort/ID: 6001/52099/RemoteDriverImpla304eaa8 
2023-06-26 22:34:52,538 [262405704]   INFO - ution.rmi.RemoteProcessSupport -  
2023-06-26 22:34:52,555 [262405721]   INFO - atabaseCredentialsAuthProvider - Connecting as: ExBot 
2023-06-26 22:34:52,555 [262405721]   INFO - .DatabaseConnectionEstablisher - Connecting to: jdbc:mysql://91.149.xxx.xxx:3306/ExLandSite 
2023-06-26 22:35:08,444 [262421610]   WARN - .DatabaseConnectionEstablisher - Connecting to: jdbc:mysql://91.149.xxx.xxx:3306/ExLandSite 
2023-06-26 22:35:08,444 [262421610]   WARN - .DatabaseConnectionEstablisher - Connection reset 
2023-06-26 22:35:08,445 [262421611]   WARN - alects.mysql.MysqlErrorHandler - Connection reset 
java.net.SocketException: Connection reset
    at java.base/java.net.SocketInputStream.read(SocketInputStream.java:186)
    at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140)
    at com.mysql.cj.protocol.ReadAheadInputStream.fill(ReadAheadInputStream.java:107)
    at com.mysql.cj.protocol.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:150)
    at com.mysql.cj.protocol.ReadAheadInputStream.read(ReadAheadInputStream.java:180)
    at java.base/java.io.FilterInputStream.read(FilterInputStream.java:133)
    at com.mysql.cj.protocol.FullReadInputStream.readFully(FullReadInputStream.java:64)
    at com.mysql.cj.protocol.a.SimplePacketReader.readHeader(SimplePacketReader.java:63)
    at com.mysql.cj.protocol.a.SimplePacketReader.readHeader(SimplePacketReader.java:45)
    at com.mysql.cj.protocol.a.NativeProtocol.readMessage(NativeProtocol.java:540)
    at com.mysql.cj.protocol.a.NativeProtocol.readServerCapabilities(NativeProtocol.java:498)
    at com.mysql.cj.protocol.a.NativeProtocol.beforeHandshake(NativeProtocol.java:385)
    at com.mysql.cj.protocol.a.NativeProtocol.connect(NativeProtocol.java:1351)
    at com.mysql.cj.NativeSession.connect(NativeSession.java:157)
    at com.mysql.cj.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:953)
    at com.mysql.cj.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:823)
    at com.mysql.cj.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:453)
    at com.mysql.cj.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:246)
    at com.mysql.cj.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:198)
    at com.intellij.database.remote.jdbc.helpers.JdbcHelperImpl.connect(JdbcHelperImpl.java:629)
    at com.intellij.database.remote.jdbc.helpers.MysqlBaseJdbcHelper.connect(MysqlBaseJdbcHelper.java:179)
    at com.intellij.database.remote.jdbc.impl.RemoteDriverImpl.connect(RemoteDriverImpl.java:54)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:359)
    at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:200)
    at java.rmi/sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:562)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:796)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:677)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:676)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)
    Suppressed: com.intellij.database.util.AsyncTask$Frame$FrameData: Async frame data: Test Connection -> Prepare connection -> Establish database connection -> Get database credentials -> Perform database connection
2023-06-26 22:35:08,445 [262421611]   INFO - ution.rmi.RemoteProcessSupport - Terminating: 127.0.0.1:6001/RemoteDriverImpla304eaa8 
2023-06-26 22:35:08,485 [262421651]   INFO - ution.rmi.RemoteProcessSupport - Process finished with exit code 137 (interrupted by signal 9: SIGKILL) 

我尝试通过 telnet 测试连接:

telnet 91.149.xxx.xxx 3306
Trying 91.149.xxx.xxx...
Connected to leased-line-91-149-xxx-xxx.telecom.by.
Escape character is '^]'.
Connection closed by foreign host.

检查 mysql 配置的有效性时,它输出以下内容:

mysqld --validate-config
2023-06-28T19:31:32.936163Z 0 [Note] [MY-013667] [Server] Error-log destination "stderr" is not a file. Can not restore error log messages from previous run.
2023-06-28T19:31:32.939545Z 0 [Note] [MY-010747] [Server] Plugin 'FEDERATED' is disabled.
2023-06-28T19:31:32.939929Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'MyISAM'
2023-06-28T19:31:32.939955Z 0 [Note] [MY-010733] [Server] Shutting down plugin 'CSV'

值得注意的是,当我通过 portchecker.co/checking 检查端口时 - 数据包到达路由器(我可以通过路由器界面看到这一点),当我尝试通过 DataGrip 或 telnet 连接时 - 数据包没有到达路由器。

我不明白为什么我无法连接到我的数据库,我尝试了互联网上的大量文章 - 都没有用。我尝试了其他所有方法。

答案1

我自己找到了一个解决方案。更改 mysql 配置中的端口对我有帮助。我只是将端口更改为另一个端口,在路由器中打开它,一切正常,我可以连接到数据库并可以管理它。

相关内容