0
我已经学习了一些基本的MySQL,并决定把它放到Python的,我有一些更多的经验。我有PHP脚本在这个MySQL服务器上工作,所以我知道服务器正在工作。但每次我连接我得到这个错误:OperationalError:(2003,“无法连接到MySQL服务器‘mysql2.000webhost.com’(10060)”)
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支持,我假设你没有从主机上运行,这是导致错误。 –