删除表,如果存在。

  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. sql = "DROP TABLE IF EXISTS customers"
  13.  
  14. mycursor.execute(sql)
  15.  
  16. #If this page was executed with no error(s), you have successfully deleted the "customers" table.