How to Connect n8n to MySQL Database in 7 Minutes (Step-by-Step Guide)
Most businesses waste hours manually querying databases and transferring data between systems. This n8n tutorial shows how to automate MySQL connections, eliminating repetitive database work while keeping your data flowing to AI agents and other apps automatically.
Why Automate MySQL Queries with n8n
Database queries are among the most repetitive tasks in business operations. Whether you're pulling customer records, checking inventory levels, or generating reports, these manual queries consume valuable time that could be spent on higher-value work.
n8n solves this by letting you create automated workflows that connect directly to your MySQL database. Once set up, these workflows can run on schedule, trigger based on events, or feed real-time data to other systems - all without writing custom code.
Example use cases: Automatically sync customer data between your CRM and database, generate daily reports without manual queries, or feed real-time product inventory to your ecommerce platform.
Step 1: Set Up MySQL Connection in n8n
The foundation of any database automation is a secure, reliable connection. n8n makes this straightforward with its dedicated MySQL node.
At 1:15 in the video, you'll see the exact connection parameters needed:
- Add a MySQL node to your workflow
- Enter your database host IP (e.g., 192.168.0.201 for local databases)
- Specify the database name (e.g., "myDB")
- Enter credentials (username "root" in the demo)
- Set port to 3306 (MySQL default)
- Click "Test Connection" to verify
Security note: For production use, create dedicated database users with limited permissions instead of using root access.
Step 2: Create a Test Table in MySQL
Before querying data, you need a properly structured table. The tutorial demonstrates creating a simple table with:
- ID (primary key, auto-increment)
- Name (VARCHAR)
- Age (INTEGER)
- Occupation (VARCHAR)
At 2:30 in the video, you'll see how to:
- Open MySQL Workbench (or your preferred client)
- Create a new table called "n8n"
- Define columns with appropriate data types
- Insert test data using an INSERT statement
This test data (like "John Jefferson, 39, developer") will be what we query from n8n in the next step.
Step 3: Query Data in n8n
With the connection established and data available, we can now build our first automated query. At 4:10 in the video, you'll see how to:
- Select "Select Row" operation in the MySQL node
- Choose your table from the dropdown
- Execute the step to test the query
- View the returned data in n8n's interface
The initial query fetches all records, but you can add WHERE clauses to filter results. The visual query builder lets you select specific columns or write custom SQL for more complex queries.
Pro tip: Use the "Options" section to limit returned rows or sort results, just like in SQL.
Step 4: Connect to AI Agent
One of n8n's most powerful features is the ability to connect database queries directly to AI agents. At 5:45 in the video, we see how to:
- Connect the MySQL node's output to an AI agent node
- Configure the agent to process the database results
- Add a prompt like "Please describe this person"
- Execute the full workflow
The AI automatically recognizes and describes the database record ("John Jefferson is a 39-year-old developer"). This pattern can be extended to analyze trends, generate reports, or trigger actions based on database content.
Advanced Query Options
Beyond basic SELECT queries, n8n's MySQL node supports:
- INSERT operations: Add new records from forms, APIs, or other triggers
- UPDATE statements: Modify existing data based on workflow logic
- Transaction support: Group multiple operations atomically
- Parameterized queries: Safely inject dynamic values
At 6:20 in the video, the tutorial briefly shows the query options panel where you can add WHERE clauses, sorting, and limits without writing SQL. However, you can always switch to raw SQL mode for maximum flexibility.
Production Best Practices
While the tutorial uses a simple local setup, production deployments should consider:
- Connection security: Use SSH tunneling or SSL for remote databases
- Credential management: Store secrets securely in n8n's credential system
- Error handling: Add error notification nodes for failed queries
- Performance: Index frequently queried columns and limit returned data
- Monitoring: Track query execution times and failures
Scalability tip: For high-volume workflows, consider connection pooling or queuing mechanisms to avoid overwhelming your database.
Watch the Full Tutorial
See the complete 7-minute walkthrough of connecting n8n to MySQL, including the moment at 4:45 where the workflow successfully queries the test data and passes it to the AI agent.
Key Takeaways
Automating MySQL queries with n8n eliminates hours of manual database work while enabling powerful integrations with AI and other business systems.
In summary: 1) Connect n8n to MySQL in minutes 2) Query data visually or with SQL 3) Feed real-time data to AI agents 4) Build complete automated database workflows without coding.
Frequently Asked Questions
Common questions about this topic
Connecting n8n to MySQL allows you to automate database queries, sync data between systems, and feed real-time data to AI agents. This eliminates manual database queries and enables automated workflows that can trigger based on database changes.
Common use cases include customer data synchronization, inventory management, and automated reporting. Businesses using this integration typically save 5-15 hours per week on repetitive database tasks.
- Eliminates manual query work
- Enables real-time data flows
- Triggers actions based on database changes
Yes, n8n supports multiple database types including PostgreSQL, SQLite, Microsoft SQL Server, and MongoDB. The setup process is similar for most SQL databases, though connection parameters will vary.
For NoSQL databases like MongoDB, you'll use different nodes and query methods. The principles remain the same - connect once, then automate all future queries and data processing.
- Works with all major SQL databases
- NoSQL support via dedicated nodes
- Same automation benefits across platforms
You'll need the MySQL server IP address or hostname, port number (default is 3306), database name, username, and password. For local databases, you'll need the local IP (like 192.168.0.201 in the tutorial).
For cloud databases, use the provider's connection string. Always use secure credentials and consider SSH tunneling for production environments. Never expose database ports directly to the internet.
- Server IP/hostname
- Port (usually 3306)
- Database name and credentials
In the MySQL node, you can either use the visual query builder to select tables and columns or write custom SQL queries. For precise filtering, add WHERE clauses in the conditions section or directly in your SQL code.
The tutorial shows how to select all rows from a table, but you can modify this to query specific records. Advanced users can join tables, aggregate data, or call stored procedures just like in standard SQL.
- Use visual query builder or raw SQL
- Add WHERE clauses for filtering
- Supports joins and complex queries
Yes, the MySQL node supports INSERT, UPDATE, and DELETE operations alongside SELECT queries. You can create workflows that write data to MySQL based on triggers from other apps, form submissions, or scheduled events.
This is useful for logging, data collection, or updating records automatically. For example, you could create a workflow that adds new customer records to MySQL whenever a form is submitted on your website.
- Full CRUD operations supported
- Write data from any trigger
- Great for logging and data collection
n8n encrypts credentials and uses standard MySQL protocol security. For production use, we recommend several security best practices to protect your data.
First, use SSH tunneling for remote connections. Second, create dedicated database users with limited permissions. Third, store credentials in n8n's encrypted credential system. Finally, use SSL/TLS for the MySQL connection if supported by your server.
- Credentials stored encrypted
- SSH tunneling recommended
- Limited-permission users advised
Connection issues can occur for several reasons, but most are easily resolved. First, check your credentials and server IP address. Second, verify the MySQL server is running and accessible. Third, ensure no firewall is blocking port 3306.
In n8n, use the Test Connection button in the node settings to diagnose problems. Check your MySQL server logs for connection attempts if problems persist. For production systems, implement error handling workflows to notify you of connection failures.
- Test credentials first
- Check server status
- Review firewall rules
GrowwStacks specializes in building custom n8n workflows that connect to your MySQL databases and automate critical business processes. Our team handles the technical implementation so you can focus on your business.
We offer end-to-end services including secure connection setup, workflow design, error handling, and maintenance. Our clients typically see a 70-90% reduction in manual database work after implementing our automated solutions.
- Custom workflow design
- Secure implementation
- Ongoing support
Automate Your MySQL Workflows Today
Manual database queries waste time and introduce errors. Let GrowwStacks build you a custom n8n integration that keeps your data flowing automatically - typically implemented in under 2 weeks.