-
Python (
http://www.daniweb.com/forums/forum114.html)
| katharnakh | Aug 3rd, 2006 6:32 pm | |
| how do I connect to MySQL server which is firewall protected? I am facing problem connecting problem connecting remote MySQL server which is firewall protected. I used the valid user name and password, but it throws me the error
OperationalError: (2003, "Can't connect to MySQL server on 'www.myreomtemysqlserver.com' (10061)")
I want to connect from python.
I searched in Google is there anyway so that I can connect MySQL server through SSH. MySQL server is running on UNIX box.
Is there any thing I do on server or is there any package to connect to MySQL which is firewall protected?
Please help me out.
Thanks.
kath. |
| pty | Aug 3rd, 2006 9:07 pm | |
| Re: how do I connect to MySQL server which is firewall protected? Quote: Originally Posted by katharnakh I am facing problem connecting problem connecting remote MySQL server which is firewall protected. I used the valid user name and password, but it throws me the error
OperationalError: (2003, "Can't connect to MySQL server on 'www.myreomtemysqlserver.com' (10061)")
I want to connect from python.
I searched in Google is there anyway so that I can connect MySQL server through SSH. MySQL server is running on UNIX box.
Is there any thing I do on server or is there any package to connect to MySQL which is firewall protected?
Please help me out.
Thanks.
kath. | If the SSH port is open on the server's firewall (22 by default) you should be able to use a SSH tunnel to connect to mysql.
ssh -L [local port]:[mysql host]:[connect-to-port]
Then aim your connection at localhost:[local port]
For mysql the default listen port is 3306 |
| katharnakh | Aug 4th, 2006 11:38 am | |
| Re: how do I connect to MySQL server which is firewall protected? Quote: Originally Posted by pty If the SSH port is open on the server's firewall (22 by default) you should be able to use a SSH tunnel to connect to mysql.
ssh -L [local port]:[mysql host]:[connect-to-port]
Then aim your connection at localhost:[local port]
For mysql the default listen port is 3306 | I knew this concept, but thanks for your reply. But how do I implement the same in Python?
I use the following code, to connect to MySQL server, sitting remote.
import MySQLdb
db=MySQLdb.connect(host="myremote_MySQL_server.com", user="USERNAME", passwd="PASSWORD", port=3306)
Can you please tell me how do I tell MySQLdb.connect() to use the SSH tunnel, by running the above command
ssh -L [local port]:[mysql host]:[connect-to-port]
Thank you.
kath. |
| msvinaykumar | Aug 15th, 2006 5:19 pm | |
| Re: how do I connect to MySQL server which is firewall protected? Hi Kather,
Create an account in mysql which does not require SSL
that's all Boss |
| pty | Aug 16th, 2006 6:11 am | |
| Re: how do I connect to MySQL server which is firewall protected? i presume you don't have access to change the firewall settings.
i'm no python expert so i got this from here:
mytunnel.py
#!/usr/bin/python
import socket
def run(host,port):
sd = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
# connect to the given host:port
sd.connect((host, port))
except socket.error:
return 0
else:
return 1
sd.close()
open.tunnel.py
#!/usr/bin/python
import os,mytunnel
command = '/usr/bin/ssh zarski@ssh.server.com -i /root/identity-test/id_rsa -N -L 4000:localhost:3306'
val = mytunnel.run('localhost',4000)
if not val:
pipe=os.popen(command,'r')
pipe.close()
You should be able to use that principle to open a tunnel from your app then aim your db connection string's host at localhost. |
| wendymclee | Nov 10th, 2009 7:26 pm | |
| how to using ssh in MySQLdb.connect? I have the same problem. Has anyone found out how to do it?
Thanks,
Wendy
Quote: Originally Posted by katharnakh (Post 240308) I knew this concept, but thanks for your reply. But how do I implement the same in Python?
I use the following code, to connect to MySQL server, sitting remote.
import MySQLdb
db=MySQLdb.connect(host="myremote_MySQL_server.com", user="USERNAME", passwd="PASSWORD", port=3306)
Can you please tell me how do I tell MySQLdb.connect() to use the SSH tunnel, by running the above command
ssh -L [local port]:[mysql host]:[connect-to-port]
Thank you.
kath. | |
| All times are GMT -4. The time now is 1:43 pm. | |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC