How To Delete Record From MySQL Database Using Python
import mysql.connector
connection = mysql.connector.connect(
host='localhost',
user='root', password='',
port='3306',
database='test_py'
)
c = connection.cursor()
def deleteData(user_id):
delete_query = "DELETE FROM `users_2` WHERE `id` = " + user_id
c.execute(delete_query)
connection.commit()
deleteData("8")
OUTPUT:
Python MySQL Delete Record - Before |
Python MySQL Delete Record - After |