无法连接到mysql服务器,无法建立连接,因为负载过重的机器主动拒绝了它

lh80um4z  于 2021-06-25  发布在  Mysql
关注(0)|答案(1)|浏览(470)

我正在尝试用python连接到ubuntuvps上的mysql数据库,我正在使用以下代码

import pymysql

conn= pymysql.connect(host='remotehost',port='3306', 
user='user',password='password',db='db')

a = conn.cursor()

sql = 'SELECT * from `users`;'
a.execute(sql)

countrow = a.execute(sql)
print("Number of rows :",countrow)
data = a.fetchone()
print(data)

当我运行代码时,我得到以下错误 pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'remotehost' ([WinError 10061] No connection could be made because the target machine actively refused it)") 我已经检查了mysql数据库,我连接到服务器的“user”设置了“any host”主机名。我似乎无法解决这个问题。

vfhzx4xs

vfhzx4xs1#

通过注解解决 bind-address = 127.0.0.1/etc/mysql/mysql.conf.d/mysqld.cnf

相关问题