Update record from the database with where condition using python

Update keyword is used to Update the records from the table.

import mysql.connector as mysql

db = mysql.connect(
    host ="localhost",
    username= "root",
    password = "[email protected]",
    database = "realprogrammers"
)

cursor = db.cursor()

# defining the query

query = "UPDATE user SET user_name = 'Saurabhshukla018' WHERE name ='Saurabh'"

cursor.execute(query)

db.commit()

print(cursor.rowcount, "record(s) affected")
Leave a Comment