Get list of MySQL databases with python

Viewed 20427

I'm trying to get the names of all databases associated with my MySQL server via python (2.7), but am instead just getting the number of databases.

I looked around, and it seems like the only answer may be to use sys for a command line call, get the name of the databases, and proceed from there, but I can't believe that's the only way.

Current Code:

import MySQLdb

serv = MySQLdb.connect(host = "localhost", user = "root", passwd = "abcdefg")

c = serv.cursor()

print c.execute("SHOW DATABASES")

Output:

4

Thanks in advance for the help.

2 Answers
Related