[Tutor] connect to a remote machine - Linux

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Mon Jun 12 04:59:47 CEST 2006

> I'm sorry. I think I didn't explain myself well. My problem is not with 
> the database.. The part I'm not sure how to do is connect to the remote 
> computer..

Hi Patricia,

There's some confusion here.  Let's get that out in the open.

It sounds like you have a remote server.  That server provides login shell 
service through ssh, and this login shell service runs on port 22, I 
think.  But if your server is running MySQL, it is very likely that it 
provides network access to that MySQL database through port 3306.

I think you believe that ssh login access is required to access MySQL on 
your remote network server.  But this is not necessarily true: one can 
access MySQL remotely without having a login shell account into the 
machine.  That is, rather than:

     Client ----> Login through SSH ----> Execute mysql client

which is three steps, the conventional route here is:

     Client ----> Connect to networked MySQL using a database driver

which is more direct.


     MySQLdb: http://sourceforge.net/projects/mysql-python

as well as:


However, this does mean that the remote MySQL server has to be set up with 
a separate MySQL username/password account.  That is, MySQL keeps its own 
set of usernames and passwords that can be separate from the shell 

Also, mysqld --- the software that drives the MySQL server --- has to be 
enabled to work across tcp.  That requirement sounds obvious enough, but 
it is not the default in the MySQL server installs I've seen lately, so 
double check this with your database system administrator.  In short: you 
can not automatically assume that having login access to the machine will 
give you MySQL database access, and visa-versa.

Does this make sense so far?

> I read somewhere that os.popen would work, but I'm not sure if that will 
> do for me

Almost certainly no.

popen is not for external database access.  People have written database 
drivers to solve this problem for you already.  It is perhaps possible to 
bend popen() in such a way to access MySQL, but this will involve an 
amount of work to get right, and there will be a lot of ways of getting it 
wrong.  *grin*

So I'd recommend changing this question from: "How do I get popen() to 
access MySQL across a remote interface?" to a more general: "How do I 
connect to MySQL from Python?"  The link above to MySQLdb will give you 
the software necessary to connect your client to a MySQL server, and the 
link to the Devshed article is a tutorial on how to use it effectively.

Good luck!

More information about the Tutor mailing list