1. Increase
1 ImportPymysql as PS2 3 #Open a database connection4db = Ps.connect (host='localhost', user='Root', password='123456', database='Test', charset='UTF8')5 6 #Create a Cursor object7Cur =db.cursor ()8 9sql ="INSERT into USER (name,sex) VALUES (%s, $s)"Ten OneCur.execute (SQL, ('Amy' , ' women ')) A - Print("OK") - the #Commit the transaction (this must be actively committed, otherwise in the database operation increment, delete the result does not change) - Db.commit () - - #Close Cursors + cur.close () - + #Close the database ADb.close ()
2. Delete
1 ImportPymysql as PS2 3 #Open a database connection4db = Ps.connect (host='localhost', user='Root', password='123456', database='Test', charset='UTF8')5 6 #Create a Cursor object7Cur =db.cursor ()8 9Cur.execute ('DELETE from USER WHERE name= "Small Fang"')Ten OneA = Cur.execute ('SELECT * from USER')#The return value is a value of type int A - #Submit - Db.commit () the - #view the number of records - Print(a) - + #Close Cursors - cur.close () + A #Close the database atDb.close ()
Python's MySQL learning-data manipulation