Python MySQL Update

The UPDATE-SET statement is used to update any column inside the table.

MySQL Update

The following SQL query is used to update a column in the MySQL.

CopiedCopy Code
update Employee set name = 'alex' where id = 110

The same query can be used to perform update directly in the MySQL also

MySQL Update Example
CopiedCopy Code

import mysql.connector  
myconn = mysql.connector.connect(host = "localhost", user = "root",password = "naveen",database = "PythonDB")  
cur = myconn.cursor()   
try:  
    #updating the name of the employee whose id is 110  
    cur.execute("update Employee set name = 'Alex' where id = 110")  
    myconn.commit()  
except:       
    myconn.rollback()   
myconn.close()