ConnectionRefusedError:[WinError 10061]无法建立连接,因为目标计算机使用MySQL主动拒绝连接

2024-04-26 21:25:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在做一个学校项目。这是一个基本上很简单的练习,我应该创建3个表。我决定使用Python,在this guide之后,我编写了以下代码:

mydb = mysql.connector.connect(
    host = 'localhost',
    user = 'admin',
    passwd = 'admin',
    database = 'primo'
)
cursor = mydb.cursor()
cursor.execute("CREATE DATABASE primo")

当我尝试执行它时,它返回:

mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'localhost:3306' (10061 No connection could be made because the target machine actively refused it)

我想在本地运行它;如果我将“localhost”更改为“127.0.01”,则会显示端口错误(不过我认为最好使用“localhost”)


Tags: 项目代码localhosthostconnectoradminconnectmysql