a code
import pymysql # Open database connection db = pymysql.connect("localhost","root","root","db_test01" ) # Use the cursor() method to get the operation cursor cursor = db.cursor() # SQL delete statement sql = "DELETE FROM EMPLOYEE WHERE AGE > '%d'" % (20) try: # Execute the SQL statement cursor.execute(sql) # commit changes db.commit() print("delete OK") except: # rollback on error db.rollback() # close the connection db.close()
Second run results
delete OK