我有一个非常简单的代码来用 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/