how do I connect to MySQL server which is firewall protected?

Reply

Join Date: Jan 2006
Posts: 237
Reputation: katharnakh is an unknown quantity at this point 
Solved Threads: 33
katharnakh's Avatar
katharnakh katharnakh is offline Offline
Posting Whiz in Training

how do I connect to MySQL server which is firewall protected?

 
0
  #1
Aug 3rd, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 521
Reputation: pty is on a distinguished road 
Solved Threads: 37
pty's Avatar
pty pty is offline Offline
Posting Pro

Re: how do I connect to MySQL server which is firewall protected?

 
0
  #2
Aug 3rd, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2006
Posts: 237
Reputation: katharnakh is an unknown quantity at this point 
Solved Threads: 33
katharnakh's Avatar
katharnakh katharnakh is offline Offline
Posting Whiz in Training

Re: how do I connect to MySQL server which is firewall protected?

 
0
  #3
Aug 4th, 2006
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.

  1. import MySQLdb
  2.  
  3. 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.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 38
Reputation: msvinaykumar is an unknown quantity at this point 
Solved Threads: 2
msvinaykumar msvinaykumar is offline Offline
Light Poster

Re: how do I connect to MySQL server which is firewall protected?

 
0
  #4
Aug 15th, 2006
Hi Kather,
Create an account in mysql which does not require SSL
that's all Boss
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 521
Reputation: pty is on a distinguished road 
Solved Threads: 37
pty's Avatar
pty pty is offline Offline
Posting Pro

Re: how do I connect to MySQL server which is firewall protected?

 
0
  #5
Aug 16th, 2006
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
  1. #!/usr/bin/python
  2.  
  3. import socket
  4.  
  5. def run(host,port):
  6.  
  7. sd = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  8.  
  9. try:
  10.  
  11. # connect to the given host:port
  12.  
  13. sd.connect((host, port))
  14.  
  15. except socket.error:
  16.  
  17. return 0
  18.  
  19. else:
  20.  
  21. return 1
  22.  
  23. sd.close()


open.tunnel.py
  1. #!/usr/bin/python
  2.  
  3. import os,mytunnel
  4.  
  5. command = '/usr/bin/ssh zarski@ssh.server.com -i /root/identity-test/id_rsa -N -L 4000:localhost:3306'
  6.  
  7. val = mytunnel.run('localhost',4000)
  8.  
  9. if not val:
  10.  
  11. pipe=os.popen(command,'r')
  12.  
  13. 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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2009
Posts: 1
Reputation: wendymclee is an unknown quantity at this point 
Solved Threads: 0
wendymclee wendymclee is offline Offline
Newbie Poster

how to using ssh in MySQLdb.connect?

 
0
  #6
12 Days Ago
I have the same problem. Has anyone found out how to do it?

Thanks,
Wendy

Originally Posted by katharnakh View Post
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.

  1. import MySQLdb
  2.  
  3. 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.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC