【问题标题】:How to connect to a remote database server using Python?如何使用 Python 连接到远程数据库服务器?
【发布时间】:2020-02-29 03:28:37
【问题描述】:

我正在尝试使用 python 从 Windows 连接到安装在 VMware 中的 CentOS 7 上的远程数据库服务器,但我无法连接到它。我正在使用mysql.connector访问数据库,请帮我解决问题。

import mysql.connector
mydb = mysql.connector.connect(host="192.168.136.129", user="root", passwd="root", database="test", port=3306)
mycr = mydb.cursor()
mycr.execute("CREATE TABLE cat (name VARCHAR(25));")

【问题讨论】:

  • 任何错误信息?
  • 你能从你的本地盒子成功ping通192.168.136.129吗?另外,VMWare 是否正确桥接到您的网络?
  • 好的,我试试。感谢回复
  • 虚拟机和windows都ping通了。而且 VMWare 正在桥接到我的网络。”mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on '192.168.136.129:3306' (10060 A connection attempt failed because the connected party did not proper response after after一段时间,或建立连接失败,因为连接的主机没有响应)“。这是我面临的错误。

标签: mysql python-3.x linux database server


【解决方案1】:

不要使用 root 用户,可能会有一些权限问题。 尝试创建一个新用户并访问它。

【讨论】:

  • 我回家后试试。谢谢
  • 我想我应该打开一个到服务器的 ssh 隧道。你们认为它会起作用。尽快更快地需要帮助。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多