Lab 06: Query Profiling & Slow Log
Overview
Step 1: MySQL — Enable Slow Query Log
docker run -d --name mysql-lab \
-e MYSQL_ROOT_PASSWORD=rootpass \
mysql:8.0 \
--slow_query_log=ON \
--long_query_time=0 \
--log_queries_not_using_indexes=ON \
--slow_query_log_file=/var/log/mysql/slow.log \
--general_log=ON
for i in $(seq 1 30); do docker exec mysql-lab mysql -uroot -prootpass -e "SELECT 1" 2>/dev/null && break || sleep 2; done
docker exec mysql-lab mysql -uroot -prootpass -e "
SHOW VARIABLES LIKE 'slow_query_log%';
SHOW VARIABLES LIKE 'long_query_time';
SHOW VARIABLES LIKE 'log_queries_not_using_indexes';
"Step 2: Create Test Data and Run Queries
Step 3: SHOW PROFILES and SHOW PROFILE FOR QUERY
Step 4: performance_schema — Statement Statistics
Step 5: Fix Queries with Indexes and Measure Improvement
Step 6: PostgreSQL — pg_stat_statements
Step 7: Query pg_stat_statements
Step 8: Capstone — Build a Query Performance Report
Summary
Tool
DB
Purpose
Key Takeaways
Last updated
