python - WinError 10061 由于目标机器主动拒绝,无法建立连接

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)

最佳答案

这对我有用 https://www.digitalocean.com/community/questions/can-t-connect-to-mysql-server-on-ipaddress-10061

默认情况下,mysql 不允许用户从本地主机(环回网络接口(interface))外部连接,您需要启用它才能通过所有网络接口(interface)工作。

修改/etc/mysql/my.cnf

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

然后重新启动服务。 它仅在我重新启动 VM 时适用于我的 vagrant VM。

https://stackoverflow.com/questions/60871364/

相关文章:

swift - 分段选择器移除了可访问性

angular - 类型 'arrayBuffer' 上不存在属性 'File'

python-3.x - 重复的日志 Flask - Google Cloud Logging

javascript - 如何访问 react-image-gallery 中的 slideToIn

react-native - 使用 Hermes 的 React native 应用程序崩溃并显示

r - 为什么 clogit 和 bife 函数(均在 R 中)的结果不同?

react-native - React Native Webview OnLoad 调用了两次

python - 无需安装即可导入 Python 库

reactjs - 将 Ant 设计表导出为 pdf 格式

asp.net - SignalR 协商阶段发生 CORS 错误