python - 系统错误: 10054 An existing connection was forcibly closed by the remote host in python

标签 python sql database error-handling connection

我有一个非常简单的代码来用 python 连接到数据库。

import mysql.connector

connector = mysql.connector.connect(host="localhost", user="testuser", 
password="testuser", database='testdb',port='1433')

print(connector)

cur = connector.cursor()

print(cur)

上面的代码给了我以下错误:

mysql.connector.errors.OperationalError: 2055: Lost connection to MySQL server at 'localhost:1433', system error: 10054 An existing connection was forcibly closed by the remote host.

我在任何相关问题上都没有得到正确的答案。请帮我解决这个问题。

最佳答案

我了解到这个问题是在我使用 Microsoft SQL 数据库的 MySQL 连接器时发生的。我必须使用 pyodbc 连接到 SQL 数据库。

关于python - 系统错误: 10054 An existing connection was forcibly closed by the remote host in python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59856973/

相关文章:

mysql - 如何在mysql中快速导入10gb的sql文件?

database - 如何使用 Flutter 检查 Firestore 中多个文档中的特定值

python - Scipy 写入音频问题

Python file.write 创建额外的回车

mysql - 两个表和它们的主键之间的关系

ruby - 使用Ruby进行离线地理计算,可以完成吗?

python - 如何在 Python 中将这些 DMS 地理坐标转换为十进制?

php - HTML 表单加载通过 php 显示 sql 十六进制值

sql - Node.js PostgreSQL