Examples are as follows:
pymysql Import
DEF Delete_From ():
# Open the database link
db = pymysql.connect ( "localhost", "root", "123456", "the Test")
# using the cursor () method to get the cursor operating
the Cursor = db.cursor ()
# SQL statement to update data
SQL = "" "the FROM Student dELETE the WHERE ID =% S" ""% (3)
the try:
# execute SQL statements
cursor.execute (SQL)
# submitted to the database to perform
the db.commit ()
Print ( "delete data success ")
the except Exception AS E:
Print (" failed to delete the data:% S Case "% E)
# rollback when an error occurs
db.rollback ()
a finally:
# close connection cursor
cursor.close ()
# close the database connection
db .close()
def main():
Delete_From()
if __name__ == '__main__':
main()