Python MySQL Update Operation
2 min readFeb 25, 2021
The UPDATE-SET statement is used to update any column inside the table. The following SQL query is used to update a column.
- > update Employee set name = ‘alex’ where id = 110
Consider the following example.
Example
- import mysql.connector
- #Create the connection object
- myconn = mysql.connector.connect(host = “localhost”, user = “root”,passwd = “google”,database = “PythonDB”)
- #creating the cursor object
- 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()