Agar lebih lengkap:
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)
sekarang ada dua pilihan:
tables = cursor.fetchall() # return data from last query
atau ulangi kursor:
for (table_name,) in cursor:
print(table_name)