大网数据广告活动
服务器运维问答

MySQL cannot connect via SSH tunnel -- Connection refused

· 52CE 我爱测

I am trying to connect to MySQL from my MySQL GUI (Sequel Pro if it matters) using SSH tunnel. However, I keep getting the following error (mysql.log): [Note] Aborted connection 98 to db: 'example' user: 'example_user' host: 'loc…

问题原文

原帖链接 · Gasim · CC BY-SA 3.0

I am trying to connect to MySQL from my MySQL GUI (Sequel Pro if it matters) using SSH tunnel. However, I keep getting the following error (mysql.log):

[Note] Aborted connection 98 to db: 'example' user: 'example_user' host: 'localhost' (Got an error reading communication packets)

My connection settings look like the following:

  • SSH host: example.com
  • SSH port: 22
  • SSH user: example_user
  • SSH pass: ********
  • DB host: 127.0.0.1
  • DB user: example_user
  • DB password: *******
  • DB name: example
  • DB port: 3306

I can connect to SSH with no problems. I can also connect to MySQL from inside SSH (using mysql -u example_user -p -h 127.0.0.1)

However, tunneling is not working. I have AllowTcpForwarding yes in sshd_config. MySQL config has bind-address = 127.0.0.1.

I am using 16.04 LTS and MySQL Community Edition in my server.

What am I doing wrong? This is the first time I am seeing this issue.

已采纳解答

原帖链接 · Mikhail Khirgiy · CC BY-SA 3.0

You can create several tunnels via command on workstation by example:

ssh -L 10080:127.0.0.1:80 -L 10006:127.0.0.1:3306 user@server

There are: 127.0.0.1 - ip-address tunnel's destination to connect from server, 80 and 3306 destination ports, 10080 and 10006 - local workstation's ports. This will allow you to connect to MySql server and to Http server via server's localhost interface. Run command mysql -p -u db_user -P 10006 -h 127.0.0.1 database_name on workstation to connect to MySql server. You can connect to PhpMyAdmin web interface, which is allowed only from 127.0.0.1. To do it simply write address http://127.0.0.1:10080 in your browser.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-03-19)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。