【问题标题】:sqlalchemy connect to VPS databasesqlalchemy 连接到 VPS 数据库
【发布时间】:2015-02-12 12:00:35
【问题描述】:

我正在尝试从我的 PC 连接到 VPS mysql 数据库。我使用 sqlalchemy 框架,但我需要在连接之前建立 SSH 隧道。

通常的方式,当 Web 应用在 VPS 上运行时:

create_engine('mysql://user:pswd@localhost/dbname')

如何从另一台 PC 连接到该数据库。假设有连接凭据:IP、用户名、密码

【问题讨论】:

  • localhost 替换为数据库服务器的IP 地址会发生什么?
  • 当我通过 SSH 端口 22 传递 IP 时:sqlalchemy.exc.OperationalError: (OperationalError) (2013, "Lost connection to MySQL server at 'reading initial communication packet', system error: 0") 无无
  • 和 mysql 端口 3306: sqlalchemy.exc.OperationalError: (OperationalError) (2003, "Can't connect to MySQL server on 'xxx.xxx.xxx.xxx' (111)") 无无

标签: python mysql ssh sqlalchemy


【解决方案1】:

您的 MySQL 服务器只监听本地连接。让它监听外部连接:

  1. 编辑/etc/mysl/my.cnf 文件
  2. 注释掉bind-address = 127.0.0.1这一行
  3. 重启mysqld

【讨论】:

  • 没有注释。我认为我必须通过 SSH 隧道连接到 VPS,但我不知道如何。
  • 如果没有注释,你应该注释它。
  • 在 'create_engine('mysql://mysql_username:mysql_pswd@IP:3306/db_name')' 之后:sqlalchemy.exc.OperationalError: (OperationalError) (1130, "Host 'bband- dyn233.178-41-4.t-com.sk' is not allowed to connect to this MySQL server") 无 无
  • 这是另一个(特权)问题。见:stackoverflow.com/questions/1559955/…
猜你喜欢
  • 2019-03-03
  • 1970-01-01
  • 2021-04-02
  • 2021-11-02
  • 2015-04-11
  • 2013-03-15
  • 2018-02-09
  • 2020-04-05
  • 1970-01-01
相关资源
最近更新 更多