python: MYSQLdb. how to get columns name without executing select * in a big table?

后端 未结 4 1154
醉梦人生
醉梦人生 2020-12-31 09:01

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.de         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-31 09:46

    The correct way to do this would be to use "SHOW columns FROM table_name" however, you could also simply add a LIMIT to your existing query:

    cursor.execute("SELECT * FROM table_name LIMIT 0")
    print cursor.description
    

提交回复
热议问题