Delete Data from Table

We can use the Delete query to delete data from the table in MySQL.

Syntax:

DELETE FROM TABLE_NAME WHERE ATTRIBUTE_NAME = ATTRIBUTE_VALUE

Example: Delete Data from MySQL table using Python

Python3




# importing required libraries
import mysql.connector
  
dataBase = mysql.connector.connect(
  host ="localhost",
  user ="user",
  passwd ="password",
  database = "gfg"
)
 
# preparing a cursor object
cursorObject = dataBase.cursor()
  
query = "DELETE FROM STUDENT WHERE NAME = 'Ram'"
cursorObject.execute(query)
dataBase.commit()
 
# disconnecting from server
dataBase.close()


Output:

Python MySQL

Python MySQL Connector is a Python driver that helps to integrate Python and MySQL. This Python MySQL library allows the conversion between Python and MySQL data types. MySQL Connector API is implemented using pure Python and does not require any third-party library. 

This Python MySQL tutorial will help to learn how to use MySQL with Python from basics to advance, including all necessary functions and queries explained in detail with the help of good Python MySQL examples. So, let’s get started.

Similar Reads

Installation

To install the Python-mysql-connector module, one must have Python and PIP, preinstalled on their system. If Python and pip are already installed type the below command in the terminal....

Connecting to MySQL Server

We can connect to the MySQL server using the connect() method....

Creating Database

...

Creating Tables

After connecting to the MySQL server let’s see how to create a MySQL database using Python. For this, we will first create a cursor() object and will then pass the SQL command as a string to the execute() method. The SQL command to create a database is –...

Insert Data into Tables

...

Fetching Data

For creating tables we will follow the similar approach of writing the SQL commands as strings and then passing it to the execute() method of the cursor object. SQL command for creating a table is –...

Update Data

...

Delete Data from Table

To insert data into the MySQL table Insert into query is used....

Drop Tables

...

Python MySQL Exercises

...

Python MySQL Applications and Projects

We can use the select query on the MySQL tables in the following ways –...