where do you run database scripts/where are DBs 'located'?

CatDude catdude at catfolks.net
Fri May 12 17:08:07 CEST 2006


On Fri, 12 May 2006 14:01:51 +0000, John Salerno wrote:

> Ok, I've been browsing through the MySQLdb docs, and I *think* I know 
> the kind of code I need to write (connect, cursor, manipulate data, 
> commmit, etc. -- although I probably need to get more familiar with 
> actual SQL commands too), but here's my problem: I don't know where 
> these scripts are supposed to be executed, or how they are supposed to 
> 'find' the database.

I'm kind of a noob myself, but I'll see if I can't offer some useful info
anyhow.

When you issue your MySQLdb.connect, that determines where the database
actions occur. If you specify "host='localhost'", then you are trying to
connect to your local machine. If you specify "host='db.smurgle.net'",
you're trying to connect to my home db server. You can specify the
hostname in any format that your local machine understands; for example,
if you are on a Linux box, and your /etc/hosts file contains a line like:
    10.0.0.10  myDBserver
then you can use "host='myDBserver'".

This isn't so much a web programming issue as it is using MySQL's network
interface. MySQL by default uses port 3306 (I think) to handle database
connections over the network.

> But my question is, can these DB scripts be executed anywhere, and they
> will find the DB based on the connect() parameters? Or do I need to do
> something special with them? It seems like a similar problem to when you
> don't have your PYTHONPATH variable set up properly. I've tried some DB
> stuff, but it doesn't seem to work.

Your scripts that make connections can be executed from anywhere that:
1) knows how to communicate with the specified database server, and
2) has some sort of MySQL client available.

> So without actually giving you some code and tracebacks, is there any
> general advice about how to set up these scripts? Also, is there any
> better documentation than this:
> http://sourceforge.net/docman/display_doc.php?docid=32071&group_id=22307

If you are having problems, by all means post some code.

> It doesn't seem too thorough, and it also doesn't cover actual SQL
> queries that you'd have to pass to the query method. Maybe I will just
> have to find that information in a MySQL tutorial.

A couple of good MySQL tutorials would most likely be a big help. The
standard docs (the ones you pointed out) are not of a great deal of help
if you're totally new to SQL. You might want to do a Google search. This
will lead you to pages like:
http://www.kitebird.com/articles/pydbapi.html
http://www.devshed.com/c/a/Python/MySQL-Connectivity-With-Python/
and the like.

Dan




More information about the Python-list mailing list