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支持,我假設你沒有從主機上運行,這是導致錯誤。 –