Python MySQL Update Query (original) (raw)
Last Updated : 09 Mar, 2020
A connector is employed when we have to use MySQL with other programming languages. The work of MySQL-connector is to provide access to MySQL Driver to the required language. Thus, it generates a connection between the programming language and the MySQL Server.
Update Clause
The update is used to change the existing values in a database. By using update a specific value can be corrected or updated. It only affects the data and not the structure of the table.
The basic advantage provided by this command is that it keeps the table accurate.
Syntax:
UPDATE tablename SET ="new value" WHERE ="old value";
The following programs will help you understand this better.
DATABASE IN USE:
Example 1: Program to update the age of student named Rishi Kumar.
import
mysql.connector
mydb
=
mysql.connector.connect(
`` host
=
'localhost'
,
`` database
=
'College'
,
`` user
=
'root'
,
)
cs
=
mydb.cursor()
statement
=
"UPDATE STUDENT SET AGE = 23 WHERE Name ='Rishi Kumar'"
cs.execute(statement)
mydb.commit()
mydb.close()
Output:
Example 2: Program to correct the spelling of an Student named SK
import
mysql.connector
mydb
=
mysql.connector.connect(
`` host
=
'localhost'
,
`` database
=
'College'
,
`` user
=
'root'
,
)
cs
=
mydb.cursor()
statement
=
"UPDATE STUDENT SET Name = 'S.K. Anirban' WHERE Name ='SK Anirban'"
cs.execute(statement)
mydb.commit()
mydb.close()
Output:
Similar Reads
- Python MySQL Python MySQL Connector is a Python driver that helps to integrate Python and MySQL. This Python MySQL library allows the conversion between Python and MySQL data types. MySQL Connector API is implemented using pure Python and does not require any third-party library. This Python MySQL tutorial will 9 min read
- How to install MySQL Connector Package in Python MySQL is a Relational Database Management System (RDBMS) whereas the structured Query Language (SQL) is the language used for handling the RDBMS using commands i.e Creating, Inserting, Updating and Deleting the data from the databases. A connector is employed when we have to use MySQL with other pro 2 min read
- Connect MySQL database using MySQL-Connector Python While working with Python we need to work with databases, they may be of different types like MySQL, SQLite, NoSQL, etc. In this article, we will be looking forward to how to connect MySQL databases using MySQL Connector/Python.MySQL Connector module of Python is used to connect MySQL databases with 3 min read
- How to Install MySQLdb module for Python in Linux? In this article, we are discussing how to connect to the MySQL database module for python in Linux. MySQLdb is an interface for connecting to a MySQL database server from Python. It implements the Python Database API v2.0 and is built on top of the MySQL C API. Installing MySQLdb module for Python o 2 min read