How to Delete an Existing Table Using “DROP TABLE” Statement in Python


In this example we will show how to delete an existing table using the “DROP TABLE” statement in Python MySQL.

Source Code

import mysql.connector

mydb = mysql.connector.connect(
    host="localhost",
    port=3306,
    user="yourusername",
    password="yourpassword",
    db="mydatabase"
)

mycursor = mydb.cursor()

sql = "DROP TABLE us_state"

mycursor.execute(sql)

mydb.close()

# If the above code is executed with no error, the table was deleted successfully.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments