2010-08-24 44 views

回答

7

SHOW表

15個字符

45

要多一點齊全:

import MySQLdb 

connection = MySQLdb.connect(
       host = 'localhost', 
       user = 'myself', 
       passwd = 'mysecret') # create the connection 

cursor = connection.cursor()  # get the cursor 


cursor.execute("USE mydatabase") # select the database 

cursor.execute("SHOW TABLES") # execute 'SHOW TABLES' (but data is not returned) 

現在有兩個選擇:

tables = cursor.fetchall()  # return data from last query 

或迭代光標:

for (table_name,) in cursor: 
     print(table_name) 
+0

本教程鏈接不起作用 – aimzy 2014-12-17 10:29:21

+0

Pitty ...他們刪除了整個網站。所以我刪除了鏈接,謝謝注意。 – Remi 2014-12-18 12:38:16

+0

在「USE」處或附近出現語法錯誤 LINE 1:USE portal – ihue 2017-02-13 19:47:52

相關問題