Home >>Python Tutorial >Pyhton Mysql Delete
import mysql.connector mydb = mysql.connector.connect ( host=“localhost” , user=“yourusername” , passwd=“yourpassword” , database=“mydatabase” , ) mycursor = mydb.cursor ( ) sql = “DELETE FROM customers WHERE address = ‘Mountain 21’ ” mycursor.execute ( sql ) mydb.commit ( ) print ( mycursor.rowcount, “record ( s ) deleted” )It is important for you to focus on the statement of mydb.commint ( ). This is because of the fact that only because of this statement you will be allowed to make changes to the particular table. Without this statement you will not be allowed to make any changes in the table. It is also important for you to always remember to use the WHERE clause in the DELETE syntax. This is because of the fact that if you forget to use this clause then all the records that you possess will be deleted. Hence, you should always remember to use the WHERE clause while using the DELETE syntax.
import mysql.connector mydb = mysql.connector.connect ( host=“localhost” , user=“yourusername” , passwd=“yourpassword” , 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” )With this, we finish the Python sql delete part of our Python MySQL Study Guide.