MySQLdb through proxy

2019-07-09 05:05发布

问题:

I'm using the above mentioned Python lib to connect to a MySQL server. So far I've worked locally and all worked fine, until i realized I'll have to use my program in a network where all access goes through a proxy.

Does anyone now how I can set the connections managed by that lib to use a proxy? Alternatively: do you know of another Python lib for MySQL that can handle this?

I also have no idea if the if the proxy server will allow access to the standard MySQL port or how I can trick it to allow it. Help on this is also welcomed.

回答1:

I use ssh tunneling for that kind of issues. For example I am developing an application that connects to an oracle db.

In my code I write to connect to localhost and then from a shell I do:

ssh -L1521:localhost:1521 user@server.com

If you are in windows you can use PuTTY



回答2:

there are a lot of different possibilities here. the only way you're going to get a definitive answer is to talk to the person that runs the proxy.

if this is a web app and the web server and the database serve are both on the other side of a proxy, then you won't need to connect to the mysql server at all since the web app will do it for you.



回答3:

Do you have to do anything special to connect through a proxy?

I would guess you just supply the correct parameters to the connect function. From the documentation, it looks as if you can specify the host name and port number with an arguments to connect.

Like this:

connection = connect(host="dbserver.somewhere.com", port=nnnn)
# etc..