Skip to main content
MySQL MCP Server provides advanced ML and GenAI capabilities through MySQL AI and MySQL HeatWave, enabling text generation, natural language to SQL conversion, and intelligent database interactions.

Overview

The ML/GenAI tools leverage MySQL’s built-in AI capabilities:
  • Text Generation: Generate text using GenAI models with ml_generate
  • Natural Language to SQL: Convert questions to SQL with ask_nl_sql
  • Schema Discovery: Find relevant tables with retrieve_relevant_schema_information
  • HeatWave ML Help: Get guidance on AutoML features with heatwave_ask_help
  • Vector Embeddings: Create embeddings with ragify_column (see Vector Stores)

Text Generation with ml_generate

Overview

Generate text responses using MySQL’s integrated GenAI models.

Usage

"Generate a summary of customer feedback trends"
"Create a product description based on technical specifications"
"Summarize this SQL query results: [data]"
Tool: ml_generate Parameters:
  • connection_id (string, required): Database connection identifier
  • question (string, required): Text generation prompt or instruction
Returns: Generated text response

Example Workflows

Summarizing Query Results

-- First, execute a query
"Execute 'SELECT product, COUNT(*) as issues FROM support_tickets GROUP BY product' on my_connection"

-- Then generate a summary
"Generate a summary of the product support ticket distribution"

Content Generation

"Generate a welcome email for new customers mentioning our key features"
"Create a FAQ answer explaining our refund policy"
"Write a brief explanation of database normalization"

Data Analysis Insights

"Generate insights from our quarterly sales data"
"Analyze the error patterns in system logs and suggest improvements"
"Summarize customer sentiment from review comments"

Best Practices

  • Be Specific: Provide clear, detailed prompts
  • Context Matters: Include relevant data or query results in your prompt
  • Iterate: Refine prompts based on initial results
  • Length Control: Specify desired output length if needed
The ml_generate tool works on both MySQL AI and MySQL HeatWave connections.

Natural Language to SQL (NL2SQL)

Overview

Convert natural language questions directly into SQL queries and execute them automatically.

Usage

"What is the average delay incurred by flights?"
"Show me the top 5 customers by total order value"
"How many support tickets were opened last month?"
Tool: ask_nl_sql Parameters:
  • connection_id (string, required): Database connection identifier
  • question (string, required): Natural language question about your data
Returns:
  • Generated SQL query
  • Query execution results

How It Works

  1. Schema Analysis: Analyzes your database schema
  2. Query Generation: Converts natural language to SQL
  3. Automatic Execution: Runs the generated query
  4. Results Return: Provides both SQL and results

Example Questions

Analytics Questions

"What is the average order value by customer segment?"
"Show monthly revenue trends for the last year"
"Which products have the highest return rate?"

Operational Questions

"How many active users do we have?"
"List all orders pending shipment"
"Show me employees hired in the last 6 months"

Comparison Questions

"Compare sales performance between regions"
"What's the difference in customer satisfaction between product categories?"
"Show the top and bottom performing stores"

Generated SQL Examples

Question: “What is the average delay incurred by flights?”
SELECT AVG(arrival_delay) as avg_delay
FROM flights
WHERE arrival_delay IS NOT NULL;
Question: “Show me the top 5 customers by total order value”
SELECT customer_id, customer_name, SUM(order_total) as total_value
FROM orders
JOIN customers ON orders.customer_id = customers.id
GROUP BY customer_id, customer_name
ORDER BY total_value DESC
LIMIT 5;

Tips for Better Results

  • Use Proper Terminology: Reference actual table/column concepts
  • Be Specific: Include time ranges, filters, and limits
  • Test Incrementally: Start simple, then add complexity
  • Review SQL: Check the generated SQL for accuracy
Always review the generated SQL before relying on results for critical decisions. While NL2SQL is powerful, complex questions may require manual SQL refinement.

Schema Discovery

Overview

Automatically identify relevant tables and schemas for a natural language question.

Usage

"Which tables contain employee salary information?"
"Show me the schema for customer-related tables"
"What tables have pricing data?"
Tool: retrieve_relevant_schema_information Parameters:
  • connection_id (string, required): Database connection identifier
  • question (string, required): Natural language question or topic
Returns: DDL (Data Definition Language) statements for relevant tables

Example Output

Question: “Which tables contain employee information?”
CREATE TABLE employees (
  id INT PRIMARY KEY,
  first_name VARCHAR(50),
  last_name VARCHAR(50),
  email VARCHAR(100),
  department_id INT,
  hire_date DATE,
  salary DECIMAL(10,2)
);

CREATE TABLE departments (
  id INT PRIMARY KEY,
  name VARCHAR(100),
  manager_id INT
);

CREATE TABLE employee_performance (
  employee_id INT,
  review_date DATE,
  rating INT,
  comments TEXT
);

Use Cases

Database Exploration

"What tables exist for order processing?"
"Show me all tables related to inventory management"

Data Modeling

"Which tables reference the customers table?"
"Show me the schema for the sales data model"

Query Planning

"What tables do I need to join to get customer purchase history?"
"Show me tables with product pricing information"
This tool is especially useful before writing complex queries or when exploring unfamiliar databases.

HeatWave ML Help (NL2ML)

Overview

Ask natural language questions about MySQL HeatWave AutoML features and get guidance on using machine learning capabilities.

Usage

"How do I train a model in HeatWave AutoML?"
"What machine learning algorithms does HeatWave support?"
"How do I use ML_PREDICT_ROW?"
Tool: heatwave_ask_help Parameters:
  • connection_id (string, required): HeatWave database connection
  • question (string, required): Question about HeatWave ML
Returns: Explanation or guidance about HeatWave ML features

Example Questions

Getting Started

"What are the steps to train a machine learning model?"
"How do I prepare data for AutoML?"
"What's the difference between ML_TRAIN and ML_MODEL_LOAD?"

Model Training

"What parameters can I use with ML_TRAIN?"
"How do I specify the target column for prediction?"
"Can I train classification and regression models?"

Predictions

"How do I make predictions on new data?"
"What's the syntax for ML_PREDICT_TABLE?"
"How do I interpret prediction results?"

Model Management

"How do I list all trained models?"
"Can I export a trained model?"
"How do I delete an old model?"
The heatwave_ask_help tool only works with MySQL HeatWave connections. It will return a clear error message if used with MySQL AI connections.

Feature Compatibility

FeatureMySQL AIHeatWaveNotes
ml_generateText generation
ask_nl_sqlNatural language to SQL
retrieve_relevant_schema_informationSchema discovery
heatwave_ask_helpHeatWave-specific
ragify_columnCreate embeddings

Complete ML Workflow Example

Exploratory Analysis

# Step 1: Discover relevant tables
"Which tables contain sales data?"

# Step 2: Ask analytical questions
"What is the average order value by region?"

# Step 3: Generate insights
"Generate a summary of regional sales performance trends"

# Step 4: Create embeddings for text search (if needed)
"Add embeddings for 'product_description' column into 'description_vec' column in products table"

# Step 5: Perform semantic search
"Search products for items similar to 'wireless headphones with noise cancellation'"

Customer Intelligence

# Analyze customer behavior
"Show me customer segments by purchase frequency"

# Generate insights
"Generate insights about customer churn patterns from the segment data"

# Natural language queries
"Which customers haven't purchased in the last 90 days?"
"What products do high-value customers prefer?"

Support Ticket Analysis

# Query ticket data
"How many support tickets were resolved last week?"

# Embed ticket descriptions
"Add embeddings for 'description' column into 'description_vec' column in tickets table"

# Semantic search for similar issues
"Search tickets for issues similar to 'login timeout error'"

# Generate summary
"Generate a summary of common support issues from last month"

Best Practices

Query Optimization

  • Start Simple: Begin with basic questions, add complexity gradually
  • Validate Results: Always verify generated SQL and results
  • Use Filters: Include time ranges and limits to improve performance
  • Index Appropriately: Ensure relevant columns are indexed

Prompt Engineering

  • Be Explicit: “Show the top 5…” instead of “Show some…”
  • Provide Context: Mention table names if you know them
  • Specify Format: “as a percentage”, “rounded to 2 decimals”
  • Include Constraints: Date ranges, status filters, etc.

Error Handling

  • Review Generated SQL: Check for logical errors
  • Iterate Prompts: Rephrase if results are unexpected
  • Check Schema: Ensure referenced tables/columns exist
  • Monitor Performance: Watch for slow queries on large datasets

Common Questions

NL2SQL works best for straightforward analytical queries (aggregations, filters, joins). Complex queries with multiple subqueries or window functions may require manual refinement. Always review the generated SQL.
Yes. Execute your query first with execute_sql_tool_by_connection_id, then use ml_generate to summarize the results. Be mindful of context limits for very large result sets.
No. Each query is independent. However, you can improve results by being more specific in your questions and using consistent terminology that matches your schema.
For MySQL HeatWave, use heatwave_ask_help to learn about AutoML features. For custom models, you’ll need to use HeatWave’s ML_TRAIN and related functions directly via SQL. The MySQL MCP Server doesn’t wrap custom model training.
retrieve_relevant_schema_information only returns table schemas (DDL) without executing queries. ask_nl_sql generates and executes a query to answer your question with actual data.
This tool only works with MySQL HeatWave connections (not MySQL AI). Verify your connection mode with list_all_connections. If you’re connected to MySQL AI, this feature isn’t available.

Next Steps

Vector Stores

Learn about RAG and semantic search

API Tools

Complete tool reference

Build docs developers (and LLMs) love