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.
print c.fetchall()
after youexecute
l = c.fetchall(); l = [ i[0] for i in l ]
as it was returning a tuple of tuples where the second item in the inner tuples was null - do you know why that would be?None
) in it.