-
Notifications
You must be signed in to change notification settings - Fork 0
AI Features
MySQLGenius supports AI-powered query tools via any OpenAI-compatible API. When configured, an AI Tools tab appears in the dashboard.
| Provider | ai_auth_style |
ai_model |
Notes |
|---|---|---|---|
| OpenAI | :bearer |
Required (e.g. gpt-4o) |
|
| Azure OpenAI |
:api_key (default) |
Optional (uses deployment default) | |
| Ollama Cloud | :bearer |
Required (e.g. gemma3:27b) |
Follows redirects automatically |
| Local Ollama | :bearer |
Required | No API key validation |
| Custom client | N/A | N/A | You handle everything |
MysqlGenius.configure do |config|
config.ai_endpoint = "https://api.openai.com/v1/chat/completions"
config.ai_api_key = ENV["OPENAI_API_KEY"]
config.ai_model = "gpt-4o"
config.ai_auth_style = :bearer
endMysqlGenius.configure do |config|
config.ai_endpoint = ENV["AZURE_OPENAI_ENDPOINT"]
config.ai_api_key = ENV["AZURE_OPENAI_API_KEY"]
config.ai_auth_style = :api_key
endMysqlGenius.configure do |config|
config.ai_endpoint = "https://api.ollama.com/v1/chat/completions"
config.ai_api_key = ENV["OLLAMA_CLOUD_KEY"]
config.ai_model = "gemma3:27b"
config.ai_auth_style = :bearer
endMysqlGenius.configure do |config|
config.ai_endpoint = "http://localhost:11434/v1/chat/completions"
config.ai_api_key = "ollama"
config.ai_model = "llama3"
config.ai_auth_style = :bearer
endMysqlGenius.configure do |config|
config.ai_client = ->(messages:, temperature:, **) {
MyAiService.chat(messages, temperature: temperature)
}
endThe callable must return an OpenAI-compatible response hash with "choices".
Help the AI understand your schema for better query generation:
config.ai_system_context = <<~CONTEXT
This is an e-commerce database.
- `users` stores customer accounts. Primary key is `id`.
- `orders` tracks purchases. Linked to users via `user_id`.
- `products` contains the product catalog.
- Soft-deleted records have `deleted_at IS NOT NULL`.
CONTEXTDescribe what you want in plain English, get SQL back. The AI sees your actual schema (tables, columns, types) to generate accurate queries.
Paste a query and its EXPLAIN output. The AI analyzes the execution plan and suggests specific index additions, query rewrites, and structural changes.
Paste any SQL query and get a plain-English explanation of what it does, how data flows, and potential pitfalls.
Analyzes your table schemas for anti-patterns: inappropriate column types, missing indexes, missing NOT NULL constraints, redundant indexes, naming inconsistencies.
Detects SQL anti-patterns (SELECT *, correlated subqueries, leading wildcards, functions on indexed columns) and suggests rewrites.
Given a query and its EXPLAIN output, recommends optimal indexes with exact CREATE INDEX statements and rationale for column ordering.
Analyzes query patterns from performance_schema and slow query logs to identify N+1 patterns, degrading performance, and full table scans.
"Why is the database slow right now?" -- analyzes PROCESSLIST, InnoDB status, key metrics, and recent slow queries to diagnose live issues.
Paste a Rails migration or DDL and get a risk assessment: will it lock the table? Is it safe during traffic? Should you use pt-online-schema-change?
When no AI configuration is set, the AI Tools tab is automatically hidden. No code changes needed.
< Configuration | Dark Theme >