# Generate SQL from natural language in chat with database using n8n and OpenAI
This automation enables natural language interaction with a MySQL database via chat, transforming user questions into executable SQL queries. Ideal for fast data analysis without requiring deep knowledge of database structure.
## Who it´s for
- Data analysts who need to write SQL quickly without memorizing schema details
- Developers automating SQL query generation
- Technical specialists using chat interfaces to interact with databases
- Teams leveraging n8n for internal analytics tools
## What the automation does
- Extracts and stores the MySQL database schema on first run
- Accepts user messages via HTTP API or manual trigger
- Uses a LangChain AI agent with OpenAI to generate SQL based on input and schema
- Safely executes valid SELECT queries and returns formatted results
- Answers structural questions (e.g., ´What tables exist?´) using cached schema
- Integrates with chat interfaces through HTTP triggers
## What´s included
- Ready-to-use n8n workflow
- Trigger and message handling logic
- Integrations with MySQL, OpenAI API, and HTTP API
- Basic text instructions for setup and adaptation
## Requirements for setup
- Access to an n8n instance
- OpenAI account with active API key
- MySQL database access (schema read and SELECT execution)
- Ability to configure HTTP endpoints for incoming messages
## Benefits and outcomes
- Faster data analysis by eliminating manual SQL writing
- Lower barrier for non-technical users
- Safe data exploration without direct production DB access
- Consistent, standardized queries via AI
- Easy integration into team’s internal tools
- Time savings on routine analytical tasks
## Important: template only
Important: you are purchasing a ready-made automation workflow template only. Rollout into your infrastructure, connecting specific accounts and services, 1:1 setup help, custom adjustments for non-standard stacks and any consulting support are provided as a separate paid service at an individual rate. To discuss custom work or 1:1 help, contact via chat
No feedback yet