I want to get the column names of a table, but there a over million data in it. So I cannot use:
cursor.execute("SELECT * FROM table_name")
print cursor.description
And in sqlite3, I do it this way
crs.execute("PRAGMA table_info(%s)" %(tablename[0]))
for info in crs:
print info
But this is not working in python mysqldb. Any one know how to do that?
Try
or
Both prevent massive amounts of data being rattled. The second one is perhaps more elegant. I've just checked, and even this works:
You can use
SHOW columns
:FYI, this is essentially the same as using
desc
:The correct way to do this would be to use
"SHOW columns FROM table_name"
however, you could also simply add aLIMIT
to your existing query:Use the following to find other information