简体   繁体   中英

WinError 10061 No connection could be made because the target machine actively refused it

import mysql.connector

mydb = mysql.connector.connect(host="localhost", user="myusername", passwd="mypassword")

print(mydb)

[WinError 10061] No connection could be made because the target machine actively refused it

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)

This worked for me https://www.digitalocean.com/community/questions/can-t-connect-to-mysql-server-on-ipaddress-10061

By default mysql doesn't allow users to be connected from outside localhost (loopback network interface), you need to enable it to work through all network interfaces.

modify the /etc/mysql/my.cnf

#default
#bind-address       = 127.0.0.1
#NEW
bind-address        = 0.0.0.0 

then restart the service . it only worked for my vagrant VM when I rebooted the VM.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

Related Question "[WinError 10061] No connection could be made because the target machine actively refused it" ConnectionRefusedError: [WinError 10061][WinError 10061] No connection could be made because the target machine actively refused it Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it pymongo.errors.ServerSelectionTimeoutError:localhost:27017:[WinError 10061]No connection could be made because the target machine actively refused it ConnectionRefusedError at /password-reset/ [WinError 10061] No connection could be made because the target machine actively refused it DJANGO EMAIL CONFIRMATION: [WinError 10061] No connection could be made because the target machine actively refused it (tkinter) ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it WinError 10061: No connection could be made because the target machine actively refused it [InfluxDB with Flask] Python Socket Programming - ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM