n8n

How to Connect MySQL Data Insights?

Turn a simple chat into a safe way to ask questions about your MySQL data. Team members type a question, the system suggests SQL, runs it when needed, and returns a clear answer with results. It is made for operations and data teams that want fast answers without writing queries by hand.

Under the hood, a one time setup loads all table names and column details from MySQL, then saves that schema to a local JSON file for speed. Each chat message reads the schema file, adds your question, and sends both to an AI Agent powered by OpenAI. The agent forms a reply and, when needed, generates a SQL statement. A regex pulls the SQL from the reply. If a query exists, the workflow runs it on MySQL, formats the rows, and shows both the text answer and the table result in the chat.

You need an OpenAI key and a MySQL database with proper access. Run the schema build once, then use the chat to explore. Expect faster self service reporting, fewer back and forth requests, and clearer answers. Great for daily checks, ad hoc analysis, and quick lookups across sales, support, finance, and operations.

What are the key features?

  • Chat Trigger collects user questions and starts the flow
  • One time schema builder lists tables, describes columns, and saves a local JSON file
  • Schema is loaded from the file on each chat for faster processing
  • OpenAI Chat Model with memory keeps recent context for better answers
  • Custom AI Agent prompt uses only schema to create safe SQL when needed
  • Regex based SQL extraction pulls the exact query from the agent reply
  • Branch logic runs SQL only if a query exists, otherwise replies instantly
  • MySQL node executes queries and a formatter prepares readable results
  • Final step combines the natural answer and the table output in one message

What are the benefits?

  • Reduce manual SQL drafting time from 15 minutes to 2 minutes per question
  • Speed up query response by up to 70 percent using a cached schema file
  • Lower data access risk since the agent sees structure but not row data
  • Cut analyst backlogs by enabling non technical users to self serve
  • Connect AI and MySQL in one place to unify question, query, and result

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with OpenAI and MySQL. See the Tools Required section above for links to create accounts with these services.
  3. In the n8n credentials manager, create an OpenAI credential. Choose API Key, paste your key from the OpenAI account API page, name the credential, and save. Test the connection if available.
  4. In the n8n credentials manager, create a MySQL credential. Enter host, port, database, user, and password. Ensure your MySQL server allows connections from n8n. Click Test to confirm access.
  5. Open the Manual Trigger path and click Test workflow. This runs the schema build: list tables, describe columns, and save the JSON file to the path defined in the file node.
  6. Check the file write node execution. Confirm the schema file path matches the read node path. If the file is missing, re run the manual trigger and verify permissions.
  7. Open the Chat Trigger node view and start a chat session in n8n. You can also use the webhook URL to send POST requests from an external client for testing.
  8. Type a simple request like list all tables to confirm instant answers without a SQL run. Then try a specific question like top 5 customers in a country to trigger SQL generation.
  9. Watch the SQL extraction node output. If no SQL is found, the flow returns the text answer. If SQL is found, confirm the MySQL node runs and the formatter shows clean rows.
  10. If MySQL queries fail, check user permissions, database name, and host firewall rules. If answers seem off, reduce model temperature in the OpenAI node and re test.
  11. When stable, publish the chat URL to your team or embed it behind your internal tools as needed.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

MySQL

Sign up

MySQL Community Edition (GPL) – Free ($0)

OpenAI

Sign up

Pay-as-you-go: GPT-5 at $1.25 per 1M input tokens and $10 per 1M output tokens

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.