Saturday , September 18 2021
Home / Python / Python MySQL Update Table

Python MySQL Update Table

10 Python MySQL Update Table

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")
1 record(s) affected

About Machine Learning

Check Also

Python MySQL Insert Into Table

4 Python MySQL Insert Into Table Python MySQL Insert Into Table¶To fill a table in …

Leave a Reply

Your email address will not be published. Required fields are marked *