Python Delete Data From MySQL Database

How To Delete Record From MySQL Database Using Python

Python Delete Data From MySQL Database


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 - Before


Python MySQL Delete Record - After
Python MySQL Delete Record - After





Share this

Related Posts

Previous
Next Post »