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.