In this video, you will learn how to retrieve records from MySQL table using Python step by step.
We’ll understand:
✔ SELECT query
✔ fetchone vs fetchall
✔ Using cursor
✔ Looping records
✔ enumerate explained
✔ Practical example
This Python MySQL tutorial is specially designed for beginners.
🧠 What is Fetch / Retrieve Records?
Fetching records means:
👉 Reading data from database table.
Here we retrieve all records from user table.
✅ Complete Example (From Your Code)
import mysql.connector
conn = mysql.connector.connect(
host="localhost",
username="root",
password="",
db="pythondb"
)
cursor = conn.cursor()
cursor.execute("select * from user")
res = cursor.fetchone()
res = cursor.fetchall()
for i in res:
for x, y in enumerate(i):
print(x, y)
🧠 Step by Step Explanation
1️⃣ Execute SELECT Query
cursor.execute("select * from user")
select * means fetch all columns.
2️⃣ fetchall()
res = cursor.fetchall()
fetchall returns:
👉 List of tuples.
Each tuple = one row.
🔁 fetchone() (Commented in Your Code)
res = cursor.fetchone()
fetchone returns:
👉 Only ONE record.
You commented it to explain another method.
So:
fetchone → single row
fetchall → all rows
3️⃣ Loop Through Records
for i in res:
i holds one row.
4️⃣ enumerate Explained
for x, y in enumerate(i):
print(x, y)
enumerate gives:
x → column index
y → column value
Example:
0 1
1 Anbu
⭐ Example Output
0 2
1 Anbu
🧠 Simple Understanding
res = [(2,"Anbu"), (3,"Raja")]
Outer loop → rows
Inner loop → columns
⭐ Key Takeaways
✔ SELECT retrieves data
✔ fetchone gets single row
✔ fetchall gets all rows
✔ enumerate gives index + value
✔ Cursor executes queries
⚠ Common Beginner Mistakes
❌ Forgetting execute()
❌ Using fetchall without select
❌ MySQL not running
❌ Wrong table name
📚 What You’ll Learn
Python MySQL fetch
SELECT query
fetchall
fetchone
enumerate
🔜 Upcoming Videos
Update Records
Delete Records
Close Connection
👍 Like
💬 Comment doubts
🔔 Subscribe for Python tutorials
python mysql fetch records
python mysql select
fetchall python mysql
python database retrieve
mysql python tutorial
learn python step by step
#Python
#MySQL
#PythonMySQL
#FetchRecords
#Database
#XAMPP
#LearnPython
#PythonBasics
#PythonTutorial
#Programming
On this page of the site you can watch the video online 🐍 Python MySQL Fetch Records Explained | SELECT Query | fetchall | Python Basics with a duration of hours minute second in good quality, which was uploaded by the user Guhan Tech Zone 22 December 2019, share the link with friends and acquaintances, this video has already been watched 106 times on youtube and it was liked by 3 viewers. Enjoy your viewing!