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.

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

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.

Hi Kather,
Create an account in mysql which does not require SSL
that's all Boss

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.

I have the same problem. Has anyone found out how to do it?

Thanks,
Wendy

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.