Using list_dbs() and list_tables function of MySQLDB with python
pythonhda
pythonhda at yahoo.com.replacepythonwithlinux
Wed Jan 15 16:59:18 EST 2003
On 15 Jan 2003 12:34:40 GMT
Gerhard Häring <gerhard.haering at opus-gmbh.net> wrote:
> sonu <u2_sonu at yahoo.co.in> wrote:
> > dear friends,
> >
> > i m using list_dbs() and list_tables() function in my application but
> > finding a problem in running this code successfully.
> >
> > The code i m using is:
> > # !/usr/bin/Python
> > import MySQLdb
> > hostname = "192.168.0.11"
> > username = "root"
>
> Using the root user like this is a very bad idea.
>
> > password = ""
>
> With an empty password even more so.
>
> > database = "test"
> > conn = MySQLdb.connect (hostname, username, password, database)
> > for db in conn.list_dbs():
> > for tbl in conn.list_tables(db[0]):
>
> You can't use SQL functions like this (using methods on the connection
> object). Instead use something like:
>
> cursor = conn.cursor()
> cursor.execute("select list_dbs()")
> for db_row in cursor.fetchall():
...
You could also write cursor.execute("show databases")
More information about the Python-list
mailing list