This article demonstrates how to execute a MySQL UPDATE query from Python to modify the MySQL table’s data.
Goals of this lesson. You’ll learn the following MySQL UPDATE operations from Python using a ‘MySQL Connector’ module.
- Update single and multiple rows, single and multiple columns
- Use a Python variable in a parameterized query to update table rows.
- Also, Update a column with date-time and timestamp values
- The role of commit and rollback in the update operation.
Further Reading:
Table of contents
Prerequisite
Before executing the following program, make sure you have the following in place −
- Username and password that you need to connect MySQL
- MySQL database table name which you want to update.
For this article, I am using a Laptop table present in my MySQL server.
If a table is not present in your MySQL server, you can refer to our article to create a MySQL table from Python.
You can also download a SQL query file, which contains SQL queries for table creation and data so that you can use this table for your UPDATE operations.