【发布时间】:2019-11-18 01:49:21
【问题描述】:
我正在尝试使用 Python 连接到 MySQL 数据库。我正在运行以下代码
import mysql.connector
from mysql.connector import Error
import pyodbc
conn = mysql.connector.connect(host='localhost',
database='data1',
user='username',
password='xxxx')
并得到错误信息
InterfaceError: Can't connect to MySQL server on 'localhost:3306' (10061 No connection could be made because the target machine actively refused it)
【问题讨论】:
-
安装 MySQL 服务器? :)
-
没有本地 MySQL 服务器在运行或防火墙阻止了连接。
-
@FlashThunder 我正在使用 MSSQLSERVER
-
@PankajGarg 所以难怪它不起作用......你正试图在它上面使用
mysql连接器。 -
@KlausD。在服务中,它显示 MSSQLSERVER 正在运行。以及如何检查防火墙是否阻止了连接。
标签: python mysql sql python-3.x database