demo_mysql_delete_escape.py:
import mysql.connector mydb = mysql.connector.connect( host="localhost", user="myusername", passwd="mypassword", database="mydatabase" ) mycursor = mydb.cursor() sql = "DELETE FROM customers WHERE address = %s" adr = ("Yellow Garden 2", ) mycursor.execute(sql, adr) mydb.commit() print(mycursor.rowcount, "record(s) deleted")
➜ begtut>python demo_mysql_delete_escape.py
1 record(s) deleted