我正在尝试连接到 AWS 托管的 (RDS) MariaDB 数据库(引擎版本 10.6.14)。该数据库托管在私有子网上,但可以通过堡垒主机访问。我使用 SSH 隧道将 MariaDB 服务器绑定到我的本地主机。
我使用 DBeaver 或 python 脚本成功连接、查询并与 MacOS 机器上的数据库交互。
但是我还需要通过我的 Linux 机器(Ubuntu 22)连接到该实例。我可以成功建立 SSH 隧道,但是当我尝试连接到数据库时出现以下错误:
错误 2013 (HY000):在“握手:读取初始通信包”时与服务器失去连接,系统错误:11
无论我是否使用:
- 命令行
mysql -u <my_user> -h 127.0.0.1 -P 3306 --password=<mypw>
- 与我在 MacOS 机器上使用的 Python 脚本完全相同
DBeaver 客户端返回以下错误:
流意外结束,从 4 中读取 0 个字节(套接字已被服务器关闭)
注意:mysql --version 返回
mysql Ver 15.1 Distrib 10.6.15-MariaDB,适用于 debian-linux-gnu (x86_64),使用 EditLine 包装器
我的 ssh 隧道设置命令:
ssh -i <my_pem_key_path.pem> -L 3306:<aws_host_url>:3306 <bastion_user>@<bastion_host> -N -f
我尝试过的事情
- 完全禁用我的防火墙
- 将 MariaDB 集群的大小从 db.t3.small 增加到 db.t3.large
- 经过三重检查,我在两台机器上使用相同的凭据
- 尝试了不同的网络
- 用 localhost 替换 127.0.0.1
- 重新安装 mysql/mariadb 客户端
- 以及各种会话变量编辑
如果它有用,telnet localhost 3306 返回:
尝试 127.0.0.1... 已连接到 127.0.0.1。转义字符为“^]”。连接已由外部主机关闭。
配置文件
我的.cnf:
# The MariaDB configuration file
#
# The MariaDB/MySQL tools read configuration files in the following order:
# 0. "/etc/mysql/my.cnf" symlinks to this file, reason why all the rest is read.
# 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.
#
# If you are new to MariaDB, check out https://mariadb.com/kb/en/basic-mariadb-articles/
#
# This group is read both by the client and the server
# use it for options that affect everything
#
[client-server]
# Port or socket location where to connect
# port = 3306
socket = /run/mysqld/mysqld.sock
# Import all .cnf files from configuration directory
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/
/etc/mysql/conf.d/mysql.cnf:
# Copyright (c) 2015, 2023, Oracle and/or its affiliates.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2.0,
# as published by the Free Software Foundation.
#
# This program is also distributed with certain software (including
# but not limited to OpenSSL) that is licensed under separate terms,
# as designated in a particular file or component or in included license
# documentation. The authors of MySQL hereby grant you an additional
# permission to link the program and your derivative works with the
# separately licensed software that they have included with MySQL.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License, version 2.0, for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
# The MySQL Client configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
[mysql]
/etc/mysql/conf.d/mysqldump.cnf:
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
/etc/mysql/mariadb.conf.d/50-client.cnf:
#
# This group is read by the client library
# Use it for options that affect all clients, but not the server
#
[client]
# Example of client certificate usage
#ssl-cert = /etc/mysql/client-cert.pem
#ssl-key = /etc/mysql/client-key.pem
#
# Allow only TLS encrypted connections
#ssl-verify-server-cert = on
# This group is *never* read by mysql client library, though this
# /etc/mysql/mariadb.cnf.d/client.cnf file is not read by Oracle MySQL
# client anyway.
# If you use the same .cnf file for MySQL and MariaDB,
# use it for MariaDB-only client options
[client-mariadb]
/etc/mysql/mariadb.conf.d/50-mysql-clients.cnf:
#
# These groups are read by MariaDB command-line tools
# Use it for options that affect only one utility
#
[mysql]
[mysql_upgrade]
[mysqladmin]
[mysqlbinlog]
[mysqlcheck]
[mysqldump]
[mysqlimport]
[mysqlshow]
[mysqlslap]
/etc/mysql/mariadb.conf.d/60-galera.cnf
#
# * Galera-related settings
#
# See the examples of server wsrep.cnf files in /usr/share/mysql
# and read more at https://mariadb.com/kb/en/galera-cluster/
[galera]
# Mandatory settings
#wsrep_on = ON
#wsrep_cluster_name = "MariaDB Galera Cluster"
#wsrep_cluster_address = gcomm://
#binlog_format = row
#default_storage_engine = InnoDB
#innodb_autoinc_lock_mode = 2
# Allow server to accept connections on all interfaces.
#bind-address = 0.0.0.0
# Optional settings
#wsrep_slave_threads = 1
#innodb_flush_log_at_trx_commit = 0
服务器错误日志
2023-09-30 8:30:14 0 [Note] Starting MariaDB 10.6.14-MariaDB-log source revision as process 460
2023-09-30 8:30:14 0 [Note] RocksDB: 2 column families found
2023-09-30 8:30:14 0 [Note] RocksDB: Column Families at start:
2023-09-30 8:30:14 0 [Note] cf=default
2023-09-30 8:30:14 0 [Note] write_buffer_size=67108864
2023-09-30 8:30:14 0 [Note] target_file_size_base=67108864
2023-09-30 8:30:14 0 [Note] cf=__system__
2023-09-30 8:30:14 0 [Note] write_buffer_size=67108864
2023-09-30 8:30:14 0 [Note] target_file_size_base=67108864
2023-09-30 8:30:14 0 [Note] RocksDB: Table_store: loaded DDL data for 0 tables
2023-09-30 8:30:14 0 [Note] RocksDB: global statistics using get_sched_indexer_t indexer
2023-09-30 8:30:14 0 [Note] MyRocks storage engine plugin has been successfully initialized.
2023-09-30 8:30:14 0 [Note] InnoDB: Compressed tables use zlib 1.2.13
2023-09-30 8:30:14 0 [Note] InnoDB: Number of pools: 1
2023-09-30 8:30:14 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
2023-09-30 8:30:14 0 [Note] InnoDB: Using Linux native AIO
2023-09-30 8:30:14 0 [Note] InnoDB: Initializing buffer pool, total size = 1073741824, chunk size = 134217728
2023-09-30 8:30:14 0 [Note] InnoDB: Completed initialization of buffer pool
2023-09-30 8:30:14 0 [Note] InnoDB: 128 rollback segments are active.
2023-09-30 8:30:14 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2023-09-30 8:30:14 0 [Note] InnoDB: Setting file '/rdsdbdata/db/innodb/ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2023-09-30 8:30:14 0 [Note] InnoDB: File '/rdsdbdata/db/innodb/ibtmp1' size is now 12 MB.
2023-09-30 8:30:14 0 [Note] InnoDB: 10.6.14 started; log sequence number 742767426; transaction id 38302
2023-09-30 8:30:14 0 [Note] InnoDB: Loading buffer pool(s) from /rdsdbdata/db/innodb/ib_buffer_pool
2023-09-30 8:30:14 0 [Note] Server socket created on IP: '0.0.0.0'.
2023-09-30 8:30:14 0 [Note] Server socket created on IP: '::'.
2023-09-30 8:30:14 0 [Note] /rdsdbbin/mysql/bin/mysqld: ready for connections.
Version: '10.6.14-MariaDB-log' socket: '/tmp/mysql.sock' port: 3306 managed by https://aws.amazon.com/rds/
2023-09-30 8:30:15 0 [Note] InnoDB: Buffer pool(s) load completed at 230930 8:30:15
----------------------- END OF LOG ----------------------