Open a conversation with SQL.
Connect with Connector/Python and use the downloadable lab fixture deliberately.
01 The idea
MySQL is a separate server; installing its Python connector does not install or start that server. The workbench provides a local Docker Compose service, environment configuration, and a mysql_lab context manager. That helper connects to the dedicated practice database, creates temporary fixture tables for this connection, and cleans up the connection at the end. Each lesson starts from the same four tasks and two projects, so examples can be run independently.
02 The experiment
Read it once. Predict what will happen. Then copy it into a .py file and run it in your local Python setup.
from lab_support import mysql_lab
with mysql_lab() as (connection, cursor):
cursor.execute("SELECT COUNT(*) AS total FROM lab_tasks")
row = cursor.fetchone()
print(f"Connected: {row['total']} practice tasks")Connected: 4 practice tasks
03 Under the hood
- 1
Download and unpack the workbench, create .env from .env.example, set local practice passwords, install requirements, and start MySQL before running this module. The Workbench page provides the exact commands.
- 2
A connection represents a server session; a cursor issues statements and retrieves results. The helper requests dictionary rows and buffered results to make these small examples easy to inspect.
- 3
Only lab_projects and lab_tasks temporary tables are seeded. They disappear with the session, so this teaching fixture is not a persistent application database. Build a persistent schema deliberately when you move beyond the exercises.
04 Your turn, builder
Query the number of practice projects and print the result.
Reveal one possible solution +
from lab_support import mysql_lab
with mysql_lab() as (connection, cursor):
cursor.execute("SELECT COUNT(*) AS total FROM lab_projects")
print(cursor.fetchone()["total"])05 Check your signal
Does pip installing the connector start a MySQL server?
Experiment. Logged.
When you can explain the idea and make the example your own, mark it complete. Your log stays in this browser.
Keep exploring
Go deeper with the official Python guide ↗.