Python MySQL Update Table¶
You can update existing records in a table by using the “UPDATE” statement:
In [22]:
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="",
database="itronix"
)
mycursor = mydb.cursor()
sql = "UPDATE customers SET address = 'Detroit' WHERE address = 'Ludhiana'"
mycursor.execute(sql)
mydb.commit()
print(mycursor.rowcount, "record(s) affected")