【发布时间】:2014-05-13 19:34:44
【问题描述】:
我一直在学习一些基本的 MySQL,并决定将它放入我有更多经验的 Python 中。我有 PHP 脚本在这个 MySQL 服务器上运行,所以我知道服务器正在运行。但是每次连接时都会出现此错误:
Traceback (most recent call last):
File "E:/Geekster_Bot/Geekster_Bot Code/Geekster_Bot_alpha_API_MySQL", line 6, in <module>
db="MY DATABASE")# name of the data base
File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 81, in Connect
return Connection(*args, **kwargs)
File "C:\Python27\lib\site-packages\MySQLdb\connections.py", line 187, in __init__
super(Connection, self).__init__(*args, **kwargs2)
OperationalError: (2003, "Can't connect to MySQL server on 'mysql2.000webhost.com' (10060)")
我真的不知道为什么。我已经打开了 MySQL 端口(3306),就像我说的,服务器/数据库正在工作。有什么想法吗?
这是整个MySQL连接的代码;
import MySQLdb
db = MySQLdb.connect(host="mysql2.000webhost.com", # your host, usually localhost
user="MY USER", # your username
passwd="MY PASSWORD", # your password
db="MY DATABASE")# name of the data base
#you must create a Cursor object. It will let
#you execute all the queries you need
cur = db.cursor()
#Use all the SQL you like
cur.execute("SELECT * twitch_follows_ign")
#print all the first cell of all the rows
for row in cur.fetchall() :
print row[0]
所有被屏蔽的数据都输入正确。
【问题讨论】:
-
000webhost 不允许外部 MySQL 连接,并且由于免费帐户不支持 Python,我假设您没有从主机运行它,这会导致错误。
标签: python mysql operationalerror