A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python/deleting-element-from-table-in-mysql-using-python/ below:

Deleting Element from Table in MySql using Python

Deleting Element from Table in MySql using Python

Last Updated : 23 Jul, 2025

Prerequisite: Python: MySQL Create Table

In this article, we are going to see how to get the size of a table in MySQL using Python. Python allows the integration of a wide range of database servers with applications. A database interface is required to access a database from Python. MySQL Connector-Python module is an API in python for communicating with a MySQL database. 

Approach:

DELETE FROM TABLE_NAME  WHERE Column Name = 'Value';

Example 1:

In this example we are using this database table with the following query;

Below is the implementation:

Python3
# Establish connection to MySQL database
import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="root",
  password="root123",
  database = "geeks"
  )
mycursor = mydb.cursor()

query = " DELETE FROM EMPLOYEE  WHERE INCOME = '5000';"
mycursor.execute(query)
mydb.commit()

print(mycursor.rowcount, "record(s) deleted")
mydb.close()

Output:

1 record(s) deleted

After deleting the element our table looks like this:

Example 2:

In this example we are going to delete the same table with a different column name:

Python3
# Establish connection to MySQL database
import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="root",
  password="root123",
  database = "geeks"
  )
mycursor = mydb.cursor()

query = " DELETE FROM EMPLOYEE  WHERE LAST_NAME = 'Mohan';"
mycursor.execute(query)
mydb.commit()

print(mycursor.rowcount, "record(s) deleted")
mydb.close()

Output:

1 record(s) deleted

After deleting the element our table looks like this:



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4