I am writing some python code to query a remote sql database. I can do this in a command line by setting up port forwarding and, in a different shell, running a mysql server. However I cant think of a way of doing this in python - is there a python module which would set up port forwarding, then return control back to the python script (and even better if I can periodically check to see if the port forwarding is still active!) TIA, Jack
Asked
Active
Viewed 342 times
0
-
I'm not entirely sure what you are asking. If you just want to connect to a remote MySQL server take a look at this question: http://stackoverflow.com/questions/372885/how-do-i-connect-to-a-mysql-database-in-python. However, you mention port forwarding. I don't understand how that is related to connecting to MySQL? Also, you mention that in a different shell you run a MySQL server. Do you mean that you run a MySQL client? Why would you need to start the server remotely like that? Typically db servers are configured to be long-running applications that run beyond the lifetime of a shell. – Pace Apr 14 '15 at 21:58
-
He's asking if he can forward a port in python, i think its pretty clear – tenwest Apr 14 '15 at 23:50
-
@JMzance , I'm trying to do the same thing at the moment. I started where you did with setting up port forwarding in one shell and then in a different shell, connecting and querying from my remote mysql db. However, I also do not know how to combine these two actions into one python script such that once the port forwarding is set up, queries occur. Did you ever figure this out? If so, it would be great if you could share your edited code. The internet is lacking a solution to this problem. Thanks :D – dlstadther Jun 15 '16 at 14:43
-
Hi no I didnt in the end since I realised there was a better way to solve my particular problem but my advice would be use a subprocess to do it maybe? – JMzance Jun 17 '16 at 09:49