title: Conecting to MySQL in a remote server from python
body: <p>I'm using Python 3.5, pymysql 0.7.6 on MacOS X 10.12.</p>
  
  <p>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:</p>
  
  <pre><code>ssh root@XXX.XXX.XXX.XXX
  root@XXX.XXX.XXX.XXX's password: my_server_password
  </code></pre>
  
  <p>and then in the server:</p>
  
  <pre><code>mysql my_database -p
  Enter password: my_database_password
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>import pymysql
  
  cnx = pymysql.connect(host='XXX.XXX.XXX.XXX', port='3306', user='root', password='my_server_password', db='my_database')
  </code></pre>
  
  <p>And it does not work, getting as error:</p>
  
  <pre><code>pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'XXX.XXX.XXX.XXX' ([Errno 61] Connection refused)")
  </code></pre>
  
  <p>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. </p>
  
  <p>So, do you have any suggestion about what might be the issue here or if I'm missing an important bit?</p>