Overview
This node executes a custom SQL query on a MySQL database. It allows users to provide an SQL string that is run against a specified database connection, returning the query results as JSON data. This node is useful for scenarios where you need to perform dynamic or complex database queries within an n8n workflow, such as fetching specific records, aggregating data, or running administrative SQL commands.
Practical examples include:
- Retrieving user data based on dynamic filters.
- Running reports or analytics queries on demand.
- Executing maintenance or setup SQL scripts during automation.
Properties
| Name | Meaning |
|---|---|
| SQL String | The SQL query string that will be executed on the database. |
Output
The node outputs an array of JSON objects under the json field. Each object contains a single property:
queryResult: Holds the result of the executed SQL query. This can be an array of rows returned by the query or other relevant data depending on the SQL command executed.
No binary data output is produced by this node.
Dependencies
- Requires a MySQL database accessible with valid connection parameters (host, user, password, database, port).
- Reads configuration from an
.inifile located relative to the node's directory to obtain default connection settings if not provided in input. - Uses the
mysqlNode.js package to establish connections and execute queries. - Requires proper credentials and network access to the target MySQL server.
Troubleshooting
Common issues:
- Connection failures due to incorrect host, port, username, or password.
- SQL syntax errors in the provided query string.
- Missing or inaccessible
.iniconfiguration file leading to fallback failures. - Network timeouts or permission issues connecting to the database.
Error messages:
- Errors thrown during query execution are logged with "Error executing SQL query:" followed by the error details.
- To resolve, verify the SQL syntax, check database connectivity, and ensure credentials are correct.
- If the
.inifile is missing or malformed, ensure it exists at the expected path and contains valid configuration.
