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
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:
- 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 ConnectionMindsDB 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):
- Replace the values with your actual database details.
- You can also use a connection URL:
Check the connection:
or
If you need a sample MySQL database for testing, you can find open datasets at MySQL Sample Databases.
#
3. Adding a GPT AI AgentTo use GPT (like GPT-4o) for natural language Q\&A, you need an OpenAI API key.
Step 1: Create the Agent
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
#
4. Asking Questions to the Agent
You can now ask natural language questions to your agent:
- 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- Start MindsDB with Docker (see above).
- Connect your database (e.g., MySQL).
- Create a GPT agent linked to your data.
- Ask questions using SQL.
#
6. Tips and Troubleshooting
- 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 TableStep | Command/Action |
---|---|
Run MindsDB | docker run -d -p 47334:47334 -p 47335:47335 mindsdb/mindsdb:latest |
Add Database | CREATE DATABASE mysql_conn WITH ENGINE = 'mysql', PARAMETERS = {...}; |
Create GPT Agent | CREATE AGENT my_gpt_agent USING model = 'gpt-4o', ...; |
Ask a Question | SELECT answer FROM my_gpt_agent WHERE question = '...'; |
#
Final ThoughtsMindsDB 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 .