Tips on how to Delete MySQL Information in Python


First, you have to the mysql.connector. In case you are not sure of tips on how to get this setup, consult with Tips on how to Set up MySQL Driver in Python.

Tips on how to Delete MySQL Information in Python

import mysql.connector

mydb = mysql.connector.join(
  host = "localhost",
  consumer = "username",
  password = "YoUrPaSsWoRd",
  database = "your_database"
)

mycursor = mydb.cursor()
sql = "DELETE FROM prospects WHERE deal with = 'The Rockies'"
mycursor.execute(sql)

mydb.commit()

print(mycursor.rowcount, "document(s) deleted")

Stop SQL Injection in MySQL queries via Python

Specify the injected variable because the second argument to the execute command as under.

import mysql.connector

mydb = mysql.connector.join(
  host = "localhost",
  consumer = "username",
  password = "YoUrPaSsWoRd",
  database = "your_database"
)

mycursor = mydb.cursor()

sql = "DELETE FROM prospects WHERE deal with = %s"
adr = ("The Rockies", )

mycursor.execute(sql, adr)

mydb.commit()

print(mycursor.rowcount, "document(s) deleted")

Leave a Reply