我正在尝试使用Python连接到我的Web服务器MySQL(我的域MySQL服务器),但是我一直收到此错误: 2013年:查询期间与MySQL服务器的连接断开
import mysql.connector
from mysql.connector import errorcode
try:
cnx = mysql.connector.connect(user='myuser', password='mypass',
host='myhost',
database='mydb',
connect_timeout=10000)
except mysql.connector.Error as err:
if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
print("Something is wrong with your user name or password")
elif err.errno == errorcode.ER_BAD_DB_ERROR:
print("Database does not exist")
else:
print(err)
else:
cnx.close()
结果:2013年:查询期间与MySQL服务器的连接丢失
在PHP中可以正常连接到该mysql服务器。 连接到localhost MySQL(XAMPP)服务器也适用于Python。
有人知道为什么在尝试使用Python连接到Web服务器MySQL数据库时仍然出现此错误吗?
答案 0 :(得分:0)
该问题已得到解决,事实证明数据库托管设置不正确,因此由于某些原因他们没有收到我的电话。通过切换到新主机已修复该问题。