cleardb mysql 需要哪个 python 库?

Which python library required for cleardb mysql?

我知道我需要 "import MySQLdb" 连接到 MySQL 数据库。但是我们在使用"cleardb mysql"时需要导入的库名称是什么?

我正在按照下面的方式进行硬编码以进行连接,但我猜是由于错误的库,我遇到了错误。以下是我的观点来解释我的情况::

1) 我已经安装了"MySQldb",并通过import关键字导入。

2) 当我在连接语法中使用端口号时,我得到 "TypeError: an integer is required".

db = MySQLdb.connect("server_IP",3306,"uid","pwd","db_name")

所以我删除了端口号

import MySQLdb
db = MySQLdb.connect("server_IP","uid","pwd","db_name")
cur = db.cursor()

错误消失了。这是正确的方法吗?

3) 一切正常,直到我执行函数 "curson.execution("SELECT VERSION()")" 来执行 sql 查询。

curson.execution("SELECT VERSION()")

我收到如下错误

Traceback (most recent call last):
  File "<pyshell#10>", line 1, in <module>
    cursor.execute("use d_7fc249f763d6fc2")
  File "path_to\cursors.py", line 205, in execute
    self.errorhandler(self, exc, value)
  File "path_to\connections.py", line 36, in defaulterrorhandler
    raise errorclass, errorvalue
OperationalError: (2006, 'MySQL server has gone away')

所以,这是由于我导入的库造成的吗?或者,如果图书馆是正确的,那么似乎是什么问题?

端口号是第五个位置参数,而不是第二个。

db = MySQLdb.connect("server_IP", "uid", "pwd", "db_name", 3306)