I am trying to connect to a MySQL db on my ubuntu VPS with python and I am using this code
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)
When I run the code I get the following error
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)")
I have checked my MySQL db and the 'user' that I am connecting to the server with has the "Any host" hostname set. I can't seem to fix this issue.
Fixed by commenting out
bind-address = 127.0.0.1
in /etc/mysql/mysql.conf.d/mysqld.cnf