This package provides a Node-RED node for connecting to and interacting with MySQL databases. It allows users to execute SQL `query` operations, including `INSERT`, `UPDATE`, `DELETE`, and `SELECT` statements, by passing the SQL query in `msg.topic` and parameters in `msg.payload`. The results are returned in `msg.payload`, typically as an array of rows or null if no results are found. The current stable version is 3.0.0. While a specific release cadence isn't published, the project maintains an active development presence on GitHub. A key differentiator is its seamless integration into the Node-RED visual programming environment, abstracting direct `mysql` library usage into a configurable, GUI-driven node. It supports parameterized queries, both positional and named, which helps mitigate basic SQL injection risks, but explicitly warns users to remain vigilant about security. The node also offers configuration options for database reconnection timeouts and character sets.
npm install node-red-node-mysqlVerified import paths — ran on the pinned version, not inferred.
This Node-RED Function node prepares `msg.topic` and `msg.payload` to perform an `INSERT` query using named parameters, which can then be fed into a configured Node-RED MySQL database node. It includes commented-out examples for `UPDATE` and `SELECT` operations.
Always use parameterized queries (`?` for positional, `:name` for named parameters) and ensure user-provided data is passed within `msg.payload` for automatic escaping. Never concatenate raw user input directly into `msg.topic` (the SQL query string).
Upgrade your Node.js runtime environment to version 18.0.0 or later to ensure compatibility and stability.
Ensure your MySQL database and tables are configured for `UTF8MB4` character set. In the Node-RED MySQL node's configuration, verify or set the character set if the option is exposed, or refer to the underlying `node-mysql` package documentation for advanced configuration options if available.
Always connect the second (error) output of the MySQL node to an error handling mechanism (e.g., a `Catch` node, a `Debug` node for logging, or another function to send notifications). Implement robust error handling for all database interactions to prevent silent failures.
Verify the database credentials (username, password, host, port) in the Node-RED MySQL node configuration against your MySQL server settings. Ensure the user has the necessary permissions.
Correct the database name in the Node-RED MySQL node configuration, or create the database on your MySQL server if it's missing.
Check the MySQL server's status and network connectivity. In the Node-RED MySQL node configuration, you can adjust the `mysqlReconnectTime` setting (in `settings.js`) to control the retry timeout for reconnecting.
Carefully review the SQL query string in your Node-RED Function node (or wherever `msg.topic` is set). Test the query directly in a MySQL client to isolate and fix syntax issues. Ensure parameterized queries are correctly formatted.