MySQL Forums
Forum List  »  Connector/Python

MySQL-connector through SSH-tunnel
Posted by: Yoann LE NY
Date: January 14, 2016 10:14AM

Hi everybody,

I am using windows 7 with Python 3.4 (with Pycharm) and try to acces a remote mySQL-database through SSH with a private key, just like it is working with MySQL-Workbench in the following picture : http://goo.gl/TgwdYI


I use SSHTunnel (https://goo.gl/pGfD30) to setup the SSH-Tunnel as follow :


from sshtunnel import SSHTunnelForwarder

server = SSHTunnelForwarder(
("blablabla.ddns.net", 3307),
ssh_host_key=None,
ssh_username="yoann",
ssh_password=None,
ssh_private_key="E:\id_rsa",
ssh_private_key_password="pass",
remote_bind_address=('192.168.0.24', 3306))

Which works smoothly.


Then I try to connect through the MySQL-connector for Python as follow :

cnx=mysql.connector.connect(user='yoann_builder', password='pass',host="127.0.0.1", port=3307)
cnx.close()

And I got the following error :

mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on '127.0.0.1:3307' (10061 No connection could be made because the target machine actively refused it)

The problem is, to my understanding, "How to specify to the connector to use the SSH-Tunnel?"

Thanks in advance for your help.

Best Regards

Options: ReplyQuote


Subject
Written By
Posted
MySQL-connector through SSH-tunnel
January 14, 2016 10:14AM


Sorry, you can't reply to this topic. It has been closed.
This forum is currently read only. You can not log in or make any changes. This is a temporary situation.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.