AutomationFlowsAI & RAG › Chatbot Query MySQL with AI Agent

Chatbot Query MySQL with AI Agent

Original n8n title: Ai-powered Chatbot Workflow with Mysql Database Integration

ByGegenfeld @gegenfeld on n8n.io

This guide shows you how to deploy a chatbot that lets you query your database using natural language. You will build a system that accepts chat messages, retains conversation history, constructs dynamic SQL queries, and returns responses generated by an AI model. By following…

Chat trigger trigger★★★☆☆ complexityAI-powered11 nodesChat TriggerMemory Buffer WindowMy Sql ToolAgentGroq Chat
AI & RAG Trigger: Chat trigger Nodes: 11 Complexity: ★★★☆☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #2985 — we link there as the canonical source.

This workflow follows the Agent → Chat Trigger recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "nodes": [
    {
      "id": "e1055031-f1f1-44dd-8e3b-18b9f543aac2",
      "name": "When chat message received",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "position": [
        -60,
        -80
      ],
      "parameters": {},
      "typeVersion": 1.1
    },
    {
      "id": "88eaaf60-aed6-4e9d-9667-d2838a8e7f78",
      "name": "Chat History",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "position": [
        280,
        120
      ],
      "parameters": {},
      "typeVersion": 1.3
    },
    {
      "id": "a5b49dee-d5e4-4324-a7f8-1638e4e41abd",
      "name": "MySQL",
      "type": "n8n-nodes-base.mySqlTool",
      "position": [
        460,
        120
      ],
      "parameters": {},
      "typeVersion": 2.4
    },
    {
      "id": "7abfcdc7-dfc5-4627-a479-82dd38404c88",
      "name": "MySQL Schema",
      "type": "n8n-nodes-base.mySqlTool",
      "position": [
        640,
        120
      ],
      "parameters": {},
      "typeVersion": 2.4
    },
    {
      "id": "bc9dfb90-0696-4801-a5c2-741c2fd27855",
      "name": "MySQL Definition",
      "type": "n8n-nodes-base.mySqlTool",
      "position": [
        820,
        120
      ],
      "parameters": {},
      "typeVersion": 2.4
    },
    {
      "id": "fd8344a4-ee89-4365-ae36-cc39f26c47df",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        360,
        -80
      ],
      "parameters": {},
      "typeVersion": 1.7
    },
    {
      "id": "4849ec08-2ab9-46f2-bc8c-f9dad3196246",
      "name": "Groq Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGroq",
      "position": [
        100,
        120
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "400a5f98-60af-4acb-950a-085402f3502d",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        60,
        300
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "5859cd82-9d6c-4783-8ef9-44cd4d800148",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        240,
        300
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "599c02ac-7246-4cab-8bdd-1f6565ece04d",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        420,
        300
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    },
    {
      "id": "33cbfb73-10e5-428b-ba71-539be16e7bc7",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -60,
        -300
      ],
      "parameters": {
        "content": ""
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "MySQL": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Chat History": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "MySQL Schema": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Groq Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "MySQL Definition": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "When chat message received": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

This guide shows you how to deploy a chatbot that lets you query your database using natural language. You will build a system that accepts chat messages, retains conversation history, constructs dynamic SQL queries, and returns responses generated by an AI model. By following…

Source: https://n8n.io/workflows/2985/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

teste. Uses chatTrigger, agent, lmChatGroq, memoryBufferWindow. Chat trigger; 24 nodes.

Chat Trigger, Agent, Groq Chat +7
AI & RAG

pix-zap. Uses chatTrigger, agent, toolCalculator, toolWikipedia. Chat trigger; 21 nodes.

Chat Trigger, Agent, Tool Calculator +7
AI & RAG

This workflow enables multimodal file analysis using Google Gemini tools connected to a text-only LLM agent. Users can upload images, videos, audio files, or documents via a chat interface. The workfl

Agent, Google Gemini Tool, Chat Trigger +3
AI & RAG

📌 Overview This workflow automates end-to-end appointment scheduling for your business using an AI-powered chatbot. Clients can book, reschedule, or cancel meetings through a simple chat interface — n

Chat Trigger, Agent, Groq Chat +6
AI & RAG

Case 1. Uses chatTrigger, googleSheets, agent, lmChatGroq. Chat trigger; 9 nodes.

Chat Trigger, Google Sheets, Agent +4