In this video, you will learn how to update and delete records in MySQL using Python step by step.
We’ll understand:
✔ UPDATE query
✔ DELETE query
✔ Using format()
✔ commit method
✔ Practical examples
This Python MySQL tutorial is specially designed for beginners.
🧠 What is Update & Delete?
Update means:
👉 Modify existing record
Delete means:
👉 Remove record permanently
✅ UPDATE RECORD Example (From Your Code)
import mysql.connector
conn = mysql.connector.connect(
host="localhost",
username="root",
password="",
db="pythondb"
)
cursor = conn.cursor()
query = "update user set name='{}' where id='{}'".format("Siva",2)
cursor.execute(query)
conn.commit()
🧠 Step by Step Explanation
1️⃣ Update Query
query = "update user set name='{}' where id='{}'".format("Siva",2)
This updates:
name = Siva
where id = 2
2️⃣ Execute
cursor.execute(query)
Runs UPDATE command.
3️⃣ Commit
conn.commit()
Saves changes permanently.
⭐ Result
Record with id 2 updated.
⚠ Important Note
This format() method works, but:
❌ Not safe for user input
✔ Placeholders (%s) are recommended
We’ll improve this later.
✅ DELETE RECORD Example
import mysql.connector
conn = mysql.connector.connect(
host="localhost",
username="root",
password="",
db="pythondb"
)
cursor = conn.cursor()
query = "delete from user where id='{}'".format(2)
cursor.execute(query)
conn.commit()
🧠 Explanation
delete removes record
where id=2 selects which row
execute runs delete
commit saves deletion
⭐ Result
Row with id 2 removed.
🧠 Simple Understanding
UPDATE → change data
DELETE → remove data
Both need:
cursor.execute
conn.commit
⭐ Key Takeaways
✔ UPDATE modifies record
✔ DELETE removes record
✔ where clause is important
✔ commit saves changes
✔ format inserts values
⚠ Common Beginner Mistakes
❌ Forgetting WHERE condition
❌ Forgetting commit
❌ Wrong id value
❌ MySQL not running
📚 What You’ll Learn
Python MySQL update
Python MySQL delete
UPDATE query
DELETE query
🔜 Upcoming Videos
Close Connection
Mini CRUD Project
Parameterized Queries
👍 Like
💬 Comment doubts
🔔 Subscribe for Python tutorials
python mysql update
python mysql delete
update delete python mysql
mysql python crud
python database update
learn python step by step
#Python
#MySQL
#PythonMySQL
#UpdateRecords
#DeleteRecords
#CRUD
#XAMPP
#LearnPython
#PythonBasics
#PythonTutorial
#Programming