1 post tagged with "mindsdb"

View All Tags

Run MindsDB with Docker, Connect Databases, Add GPT Agent, and Query with Natural Language

This guide walks you through running MindsDB using Docker, connecting your own database, adding a GPT-based AI agent, and querying it—all in detail.

1. Running MindsDB Using Docker#

Developers running MindsDB using Docker container

follow this step-by-step deployment guide to get started on Nife’s hybrid cloud—no Docker or manual setup needed

Prerequisites:

  • Docker installed on your machine.
  • If you're new to Docker, see Install Docker for platform-specific instructions.

Start MindsDB:

docker run -d \
--name mindsdb \
-p 47334:47334 \
-p 47335:47335 \
mindsdb/mindsdb:latest
  • 47334: HTTP API & Web GUI
  • 47335: MySQL API

Once started, access the MindsDB GUI at: http://localhost:47334 Or use the API at the same port.

if you're curious about how MindsDB works behind the scenes, check out this introduction to MindsDB architecture.

2. Adding a Database Connection#

MindsDB can connect to many databases (MySQL, PostgreSQL, etc.). Here’s how to add a MySQL database:

SQL Command (run in MindsDB SQL editor or via API):

CREATE DATABASE mysql_conn
WITH ENGINE = 'mysql',
PARAMETERS = {
"host": "your-mysql-host",
"port": 3306,
"database": "your_db_name",
"user": "your_db_user",
"password": "your_db_password"
};
  • Replace the values with your actual database details.
  • You can also use a connection URL:
CREATE DATABASE mysql_conn
WITH ENGINE = 'mysql',
PARAMETERS = {
"url": "mysql://user:password@host:3306/db_name"
};

Check the connection:

SHOW DATABASES;

or

SELECT * FROM mysql_conn.your_table LIMIT 5;

If you need a sample MySQL database for testing, you can find open datasets at MySQL Sample Databases.

3. Adding a GPT AI Agent#

To use GPT (like GPT-4o) for natural language Q\&A, you need an OpenAI API key.

Step 1: Create the Agent

CREATE AGENT my_gpt_agent
USING
model = 'gpt-4o',
openai_api_key = 'your_openai_api_key',
include_tables = ['mysql_conn.your_table'],
prompt_template = '
mysql_conn.your_table contains your business data.
Answer questions using this data.
';
  • model: The LLM to use (e.g., 'gpt-4o').
  • openai_api_key: Your OpenAI API key.
  • include_tables: List the tables the agent can access.
  • prompt_template: (Optional) Describe your data to help the agent answer accurately.

Not sure which model to use? Here's a comparison of GPT-4o vs Gemini vs Claude.

Step 2: Verify the Agent

SHOW AGENTS WHERE name = 'my_gpt_agent';

4. Asking Questions to the Agent#

Developer interacting with GPT agent using natural language queries about MindsDB

You can now ask natural language questions to your agent:

SELECT answer
FROM my_gpt_agent
WHERE question = 'How many customers signed up last month?';
  • The agent will use the connected data and GPT model to answer your question in natural language.

If you're new to prompt design, this OpenAI cookbook has great examples for GPT-based workflows.

5. Full Example Workflow#

  1. Start MindsDB with Docker (see above).
  2. Connect your database (e.g., MySQL).
  3. Create a GPT agent linked to your data.
  4. Ask questions using SQL.

6. Tips and Troubleshooting#

Developer troubleshooting MindsDB errors with help from a teammate
  • Multiple Databases: Repeat the CREATE DATABASE step for each data source.
  • Other Models: You can use other LLMs (Gemini, Anthropic, etc.) by changing the model and API key.
  • Data Security: Never expose your API keys in public code or logs.
  • Error Handling: If you get connection errors, double-check your database credentials and network access.

7. Reference Table#

StepCommand/Action
Run MindsDBdocker run -d -p 47334:47334 -p 47335:47335 mindsdb/mindsdb:latest
Add DatabaseCREATE DATABASE mysql_conn WITH ENGINE = 'mysql', PARAMETERS = {...};
Create GPT AgentCREATE AGENT my_gpt_agent USING model = 'gpt-4o', ...;
Ask a QuestionSELECT answer FROM my_gpt_agent WHERE question = '...';

Final Thoughts#

MindsDB bridges the gap between traditional SQL databases and modern AI models, allowing you to ask complex questions over your structured data using natural language.

With Docker for setup, SQL for control, and GPT-4o for intelligence, this workflow empowers developers, analysts, and product teams alike.

Whether you’re building an analytics dashboard, data chatbot, or intelligent reporting tool—you now have a full pipeline from data to insight using MindsDB + GPT.

You can deploy MindsDB in just a few minutes using Nife.io, a unified platform for AI applications, cloud deployment, and DevOps automation.

Explore and launch MindsDB instantly from the OpenHub App Marketplace .