How one can Replace a MySQL Desk in Python

First, you have to the mysql.connector. In case you are uncertain of how one can get this setup, confer with How one can Set up MySQL Driver in Python.

How one can Replace a MySQL Desk in Python#

import mysql.connector

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

mycursor = mydb.cursor()
sql = "UPDATE clients SET deal with = 'Stoneleigh Place' WHERE deal with = 'Abbey Highway'"
mycursor.execute(sql)
mydb.commit()

print(mycursor.rowcount, "file(s) affected")

Stop SQL Injection in your Replace Clause in Python#

import mysql.connector

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

mycursor = mydb.cursor()

sql = "UPDATE clients SET deal with = %s WHERE deal with = %s"
val = ("Stoneleigh Place", "Abbey Highway")

mycursor.execute(sql, val)
mydb.commit()

print(mycursor.rowcount, "file(s) affected")