Python MySQL CRUD

🐍 Python MySQL CRUD Example

import mysql.connector
from mysql.connector import Error
# —————————–

 1️⃣ Connect to MySQL

 

 2️⃣ Create Cursor

 

 3️⃣ Create Table

 

 4️⃣ Insert Records

 

 5️⃣ Read Records

 

 6️⃣ Update Record

 

 7️⃣ Delete Record

 

 8️⃣ Close Connection

 


 How This Script Works

  1. Connects to MySQL database testdb.

  2. Creates a table students if it doesn’t exist.

  3. Inserts new student records.

  4. Reads all records and prints them.

  5. Updates a student’s age.

  6. Deletes a student record.

  7. Closes the connection safely.

You may also like...