python - 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)
解决方案
对于您的情况,我建议使用 mariadb而不是 pymysql
pip install mariadb
推荐阅读
- asp.net-core - 服务器中的日期时间冲突 (dd/mm/yyyy)
- tabulator - 制表符 - 更改行选择列中复选框的样式
- javascript - 用于匹配 getFullYear 日期的 div id 公式
- excel - Excel 将日期范围总计拆分为每日总计
- aix - xinetd 在 HP-UX 和 AIX 上是否可配置?
- javascript - 将相互依赖的选定下拉选项组合到一个字符串中
- java - 在android布局中放置三角形并在左侧和右侧放置另一个三角形 onClick()
- python - 深度学习中的输入数据缩放问题
- javascript - 我的最后一行 Cypress 代码没有执行
- c# - 赛马林。Datagrid 显示在调试模式下工作,但在发布模式下不工作