我正在尝试在pythonanywhere上连接到我的SQL数据库并进行连接。

import MySQLdb

conn = MySQLdb.connect("MYUSERNAME.mysql.pythonanywhere-services.com","MYUSERNAME","DBPASSWORD","DBTABLENAME")

c = conn.cursor()

c.execute("SELECT * from game_db")

rows = c.fetchall()

for eachrow in rows:
    print(eachrow)


我正在从笔记本电脑上执行此操作,尝试连接时出现此错误。

_mysql_exceptions.OperationalError: (2003, "Can't connect to MySQL server on MYUSERNAME.mysql.pythonanywhere-services.com' (10060)")


我需要执行某种身份验证还是存在其他问题?
谢谢!

最佳答案

无法从pythonanywhere外部访问pythonanywhere mysql服务(除非您有付费帐户,在这种情况下,您可以使用ssh隧道:https://help.pythonanywhere.com/pages/AccessingMySQLFromOutsidePythonAnywhere/

关于python - MySQLdb连接数据库错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47729665/

10-11 05:13