A Python CLI tool that uses Google Gemini to analyze and optimize MySQL queries.
It can optionally connect to a MySQL database to retrieve table schemas and execution plans before generating recommendations.
- Explains SQL performance issues
- Suggests query improvements
- Recommends indexes
- Uses MySQL schema and
EXPLAINdata when available - Supports analysis without a database connection
git clone https://github.com/VenkatK76/query-optimizer.git
cd query-optimizer
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r Requirements.txtCreate a .env file in the project root:
GOOGLE_API_KEY=your_google_api_keyTo enable MySQL schema and execution-plan analysis, also add:
DB_HOST=localhost
DB_PORT=3306
DB_USER=your_database_user
DB_PASSWORD=your_database_password
DB_NAME=your_database_nameAnalyze a query using the configured database:
python src/main.py "SELECT * FROM orders WHERE customer_id = 42;"Analyze a query without connecting to a database:
python src/main.py --no-db "SELECT * FROM orders WHERE customer_id = 42;"The tool only provides recommendations. It does not execute optimized queries or create indexes automatically.
Review and test all generated suggestions before using them in production. :::