检查表是否存在

  1. import mysql.connector
  2.  
  3. mydb = mysql.connector.connect(
  4. host="localhost",
  5. user="myusername",
  6. passwd="mypassword",
  7. database="mydatabase"
  8. )
  9.  
  10. mycursor = mydb.cursor()
  11.  
  12. mycursor.execute("SHOW TABLES")
  13.  
  14. for x in mycursor:
  15. print(x)