Python MySQL Update Operation

Amansingh Javatpoint
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.

  1. > update Employee set name = ‘alex’ where id = 110

Consider the following example.

Example

  1. import mysql.connector
  2. #Create the connection object
  3. myconn = mysql.connector.connect(host = “localhost”, user = “root”,passwd = “google”,database = “PythonDB”)
  4. #creating the cursor object
  5. cur = myconn.cursor()
  6. try:
  7. #updating the name of the employee whose id is 110
  8. cur.execute(“update Employee set name = ‘alex’ where id = 110”)
  9. myconn.commit()
  10. except:
  11. myconn.rollback()
  12. myconn.close()

--

--

No responses yet