This project is a hands-on collection of Python scripts for learning and practicing MySQL concepts, from beginner to expert level. It uses SQLAlchemy and pandas for modern, best-practice database interaction.
- mysql_concepts_walkthrough.py: Demonstrates MySQL basics (CREATE, ALTER, INSERT, UPDATE, DELETE, TRUNCATE, DROP).
- mysql_advanced_practice.py: Covers advanced MySQL (constraints, indexes, views, stored procedures, triggers, transactions, user management, import/export).
- mysql_expert_practice.py: Explores expert topics (window functions, partitioning, error handling, performance, JSON, event scheduler, temporary tables).
- sql_practice_examples.py: Real-world SQL examples using SQLAlchemy and pandas, with best practices and comments. Connects to an existing
logistics_db(never drops/creates it).
src/– All practice scripts and exercisestests/– (For future test scripts)docs/– (For documentation and notes)requirements.txt– Python dependencies
Install all dependencies with pip install -r requirements.txt.
mysql-connector-pythonsqlalchemypandas
- Requires a running MySQL server (local or remote).
- All credentials are managed securely via a
.envfile (never hardcoded). See.env.examplefor the required variables. - Update your
.envfile with your MySQL credentials and host. - Database management:
sql_practice_examples.pyconnects to an existinglogistics_db(managed by another app; never dropped/created by this script).mysql_concepts_walkthrough.py,mysql_advanced_practice.py, andmysql_expert_practice.pycreate/drop their own demo databases (demo_db,adv_demo_db,expert_demo_db) for a clean run each time.
- If you need the schema for
logistics_db, see theapp/models.pyexample in this repo or ask your app maintainer.
-
Clone the repository
-
Create a virtual environment:
python3 -m venv .venv source .venv/bin/activate -
Install dependencies:
pip install -r requirements.txt
Run any script from the src/ folder. For example:
python src/mysql_concepts_walkthrough.py
python src/mysql_advanced_practice.py
python src/mysql_expert_practice.py
python src/sql_practice_examples.pyNote: Never hardcode credentials in production. Use a
.envfile (gitignored) andpython-dotenvfor secure credential management. All scripts in this repo follow this best practice.
- MySQL connection errors:
- Ensure MySQL server is running and accessible.
- Check your username, password, and host in the connection string.
- Install the required MySQL driver (
mysql-connector-python).
- Permission errors:
- Make sure your MySQL user has privileges to create/drop databases.
- Module not found:
- Double-check that all dependencies are installed in your virtual environment.
Feel free to add new scripts, tests, or documentation! Open issues or pull requests for improvements.