I'm using Python 3.5, pymysql 0.7.6 on MacOS X 10.12.
I'm trying to use python to access a MySQL database in a remote server. I have no problems to access from the command line using:
ssh [email protected]
[email protected]'s password: my_server_password
and then in the server:
mysql my_database -p
Enter password: my_database_password
And it works and I can do all sort of things with my database. Now, I try to do the same within python, following the documentation or the numerous examples I've found in other posts here:
import pymysql
cnx = pymysql.connect(host='XXX.XXX.XXX.XXX', port='3306', user='root', password='my_server_password', db='my_database')
And it does not work, getting as error:
pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'XXX.XXX.XXX.XXX' ([Errno 61] Connection refused)")
The credentials are the correct credentials and I've checked that the port is the correct port, as it is suggested in other posts. I suspect it might be related with the database having also a password, not just the server, but I haven't found any way of including both passwords. Indeed, I'm not sure which password should be included in the connect command, if the server password or the database password. It does not work with neither of them.
So, do you have any suggestion about what might be the issue here or if I'm missing an important bit?