import mysql.connector
# Establishing connection to the database
mydb = mysql.connector.connect(
host="localhost",
user="yourusername",
password="yourpassword",
database="yourdatabase"
)
# Creating a cursor object
mycursor = mydb.cursor()
# SQL statement to update records in the table
sql = "UPDATE yourtable SET column1 = 'newvalue' WHERE id = 1"
# Executing the SQL command
mycursor.execute(sql)
# Commit the changes to the database
mydb.commit()
# Closing the database connection
mydb.close()
print(mycursor.rowcount, "record(s) updated successfully!")