First, you will have the mysql.connector
. In case you are uncertain of tips on how to get this setup, consult with The way to Set up MySQL Driver in Python.
The way to 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 tackle = 'Stoneleigh Place' WHERE tackle = 'Abbey Highway'"
mycursor.execute(sql)
mydb.commit()
print(mycursor.rowcount, "report(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 tackle = %s WHERE tackle = %s"
val = ("Stoneleigh Place", "Abbey Highway")
mycursor.execute(sql, val)
mydb.commit()
print(mycursor.rowcount, "report(s) affected")