Connect to MySQL (replace with your credentials)
🔹 1. Setup
You need pymysql or mysql-connector-python and sqlalchemy installed:
pip install pymysql sqlalchemy
🔹 3. Export Data from Pandas to MySQL
# Write DataFrame to MySQL table
df.to_sql('new_table', con=engine, if_exists='replace', index=False)
✅ Quick Tips:
-
Use
if_exists='append'to add data without deleting existing rows. -
Ensure your MySQL user has write permissions.
-
For large data, consider batch inserts or CSV export/import.
Tags: #data-engineering #sql