【问题标题】:MySQL Connector in PythonPython 中的 MySQL 连接器
【发布时间】:2014-12-10 10:53:54
【问题描述】:

尝试连接到我的 VPS 上的 MySQL 数据库。使用以下代码时出现以下错误;

(我已经删除了我的凭据 - 但是我知道它们可以工作,因为我也将它们用于我的 PHP 开发人员。

代码

import mysql.connector as mysql
from mysql.connector import errorcode

try:
  conn = mysql.connect( user= %USER%
                        ,password=%PW%
                        ,host = %HOST%
                        ,database = %DB%
    )
except mysql.Error as err:
  if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
    print("Something is wrong with your user name or password")
  elif err.errno == errorcode.ER_BAD_DB_ERROR:
    print("Database does not exists")
  else:
    print(err)
else:
    conn.close()

错误信息

2003: Can't connect to MySQL server on '%HOST%:3306' (10060 A connection attempt failed because the connected party did not properly respond after a period of time, or established   connection failed because connected host has failed to respond)

我正在使用的连接器

http://cdn.mysql.com/Downloads/Connector-Python/mysql-connector-python-2.0.1-py3.4.msi

知道我做错了什么吗?

【问题讨论】:

  • 您为“HOST”使用的实际值是多少?
  • 我的网站域名,例如www.DOMAIN.co.uk

标签: python mysql timeout connector


【解决方案1】:

检查您的 MySQL 数据库上的 GRANT。可能是您没有被授予使用给定用户名和密码从该主机连接的权限。

MySQL 错误编号是 2003。我通常觉得 Google 搜索以查看其他人是否有此问题很有帮助:

http://dev.mysql.com/doc/refman/5.0/en/access-denied.html

客户端机器和数据库服务器之间是否有防火墙?我希望默认情况下会阻止端口 3306。如果是这样,您需要设置防火墙规则以允许从客户端 IP 通过端口 3306 访问数据库 IP。

【讨论】:

  • 我已将所有权限(真的很安全,我知道!)授予我尝试使用的用户。还是同样的问题。
  • 到从该主机 IP 连接的用户?你对此怎么说?
  • 没有遵循你的意思,达菲,对不起。我不太擅长 DB Admin!
猜你喜欢
  • 2019-06-15
  • 2018-06-27
  • 2016-01-16
  • 1970-01-01
  • 2018-08-21
  • 1970-01-01
  • 2012-12-19
  • 2019-07-19
  • 2012-10-14
相关资源
最近更新 更多