Python Program to delete a single row from a table using MySQL


In this program, you will learn how to delete a single row from a table using Python and MySQL.


create database xiith;

use xiith;

create table emp(id varchar(10), name varchar(30),salary int(10))

select * from emp;

Example: How to delete a single row from a table using Python and MySQL

import mysql.connector

myconn = mysql.connector.connect(host="localhost", user="root", passwd="12345678", database="xiith")
cur = myconn.cursor()

try:
    cur.execute("delete from emp where id='101' ")
    print("Success")

    myconn.commit()
except:
    myconn.rollback()
myconn.close()

Output:

Success