首页 > 解决方案 > MySQL (MariaDB) [WinError 10053] 已建立的连接被主机中的软件中止

问题描述

因此,我在尝试使用 mysql 时遇到了困难mysql.connector,尽管结果证明当我通过连接时它并不想合作sshtunnel 所以我转移到了 pymysql,这是我能够编写的最基本的代码:

import pymysql
from sshtunnel import SSHTunnelForwarder

with SSHTunnelForwarder(('192.168.0.x', 22), ssh_username='pi', ssh_password='*********', remote_bind_address=('localhost', 3306)) as tunnel:
    tunnel.start()
    mydb = pymysql.connect(host="localhost",
                                   user='Mashu',
                                   passwd='******',
                                   port=tunnel.local_bind_port,
                                   db='Special_Channels')

print(mydb)
query = "SELECT * FROM Daily"
cur = mydb.cursor()
data = cur.execute(query)
print(data)

虽然 cur = mydb.cursor() 它引发了一个错误:

ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine

同样在更高的层次上是:

pymysql.err.OperationalError: (2013, 'Lost connection to MySQL server during query ([WinError 10053] An established connection was aborted by the software in your host machine)')

我确定数据库和表存在,并且这个 mysql 帐户是可访问的,因为我已经打开它并在其他软件中对其进行了更改(如果有人想知道,DataGrip)

标签: pythonmysqlmariadbpymysql

解决方案


对于您的情况,我建议使用 mariadb而不是 pymysql

pip install mariadb

推荐阅读