import mysql.connector
# Establish a connection to the database
db = mysql.connector.connect(
host="localhost",
user="yourusername",
password="yourpassword",
database="yourdatabase"
)
# Create a cursor object to execute queries
cursor = db.cursor()
# Define the SQL query to delete records
query = "DELETE FROM tablename WHERE condition"
# Execute the query
cursor.execute(query)
# Commit the changes to the database
db.commit()
# Display the number of rows affected by the query
print(cursor.rowcount, "record(s) deleted")
# Close the database connection
db.close()