1

I'm using Windows on my local computer with Putty to SSH for local access to a staging database. I need to connect to MySQL using a Python/MySQL connector on Windows which goes through the Linux/Putty SSH then to MySQL. I assume I need a reverse tunnel but I'm not exactly sure how to configure it.

I have the network information, I'm just wondering how to state the SSH command for it? Also, I am on Windows 8 but I just got advice to go to Windows 10 instead.

Thanks

  • If your trying to access a MySQL database, all you really need is MySQL workbench.. You can set up a connection that way.. – ryekayo Jan 9 '17 at 20:11
  • I'm actually trying to access a MySQL database through Python to fetch and feed the data into another platform. The majority of the code is in Python. – Skys_ Jan 9 '17 at 20:14
  • Ok so you probably need a 3rd party library with Python which im assuming you already have... Then you need to configure MySQL to accept connections from your Windows IP.. Im pretty sure that's all you need – ryekayo Jan 9 '17 at 20:16
  • I do have a connector for MySQL/Python. You are probably right except the administrator gave me access through SSH/Putty. I'm the third party to the MySQL database. – Skys_ Jan 9 '17 at 20:24
  • Ok, well the DBA needs to make sure that your windows IP is added to the mysql user's table. Once that is done, you should be good to go. – ryekayo Jan 9 '17 at 20:53
1

Essentially, what you're aiming for is to open a TCP port on a local machine which connects to the MySQL database running on a remote machine; with the traffic tunneled through SSH.

I'm assuming you can already connect to the remove machine via SSH; that's a different question all together. I don't have Windows, so bare with me, but here's how to setup the tunnel in Putty: https://the.earth.li/~sgtatham/putty/0.67/htmldoc/Chapter3.html#using-port-forwarding

To configure the tunnel you need to...

  1. Know the port MySQL is listening on.
  2. Choose a local port to connect to (if you don't have MySQL running locally, you can use the same port number.

Once the tunnel is open, configure your MySQL connection in Python to use the local port.

For example, if you were connecting with the MySQL client the command would look like this: mysql -uUSER -pPASSWORD --port LOCAL_PORT DATABASE. That would establish a connection with localhost, which SSH will intercept and forward to the remote MySQL instance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.