我正在尝试用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”主机名。我似乎无法解决这个问题。
1条答案
按热度按时间vfhzx4xs1#
通过注解解决
bind-address = 127.0.0.1
在/etc/mysql/mysql.conf.d/mysqld.cnf