Can';不能用Python连接到Web服务器mysql,但它';s在Php中运行良好

Can';不能用Python连接到Web服务器mysql,但它';s在Php中运行良好,python,mysql,Python,Mysql,我正试图用Python连接到我的Web服务器MySQL(我的域MySQL服务器),但我一直遇到以下错误: 2013:查询过程中与MySQL服务器的连接中断 import mysql.connector from mysql.connector import errorcode try: cnx = mysql.connector.connect(user='myuser', password='mypass', host='myho

我正试图用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服务器的连接中断

连接到此mysql服务器在PHP中工作正常。 连接到本地主机MySQL(XAMPP)服务器也可以使用Python


你知道为什么我在尝试用Python连接到Web服务器MySQL数据库时总是遇到这个错误吗?

问题已经解决,原来托管数据库的设置不好,所以出于某种原因,他们没有收到我的呼叫。已通过切换到新主机解决此问题。

在何处/何时出现此错误?请注意,如果没有发生异常,try/except上的and
else
block将运行,因此,如果连接成功,那么连接将关闭。什么是“webserver mysql”,什么是“localhost mysql”。。。您是否正在尝试一些远程应用程序服务器,如wamp?localhost mysql->我的意思是Xampp服务器和Web服务器mysql->My mysql server for My domainNullman:这个错误被异常捕获您有任何代理吗?