1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00
node-red-nodes/storage/mysql
2021-03-16 08:24:06 +00:00
..
locales/en-US added i18n help files (#766) 2021-03-12 13:17:23 +00:00
68-mysql.html added i18n help files (#766) 2021-03-12 13:17:23 +00:00
68-mysql.js Update 68-mysql.js 2021-03-16 08:24:06 +00:00
LICENSE Update licenses and packages for all nodes 2016-11-06 20:26:19 +00:00
package.json undo mysql change again 2021-03-14 17:54:31 +00:00
README.md mysql: add charset option (defaults as-is to old UTF8) 2020-04-18 18:03:59 +01:00

node-red-node-mysql

A Node-RED node to read and write to a MySQL database.

Install

Either use the Node-RED Menu - Manage Palette - Install, or run the following command in your Node-RED user directory - typically ~/.node-red

npm i node-red-node-mysql

Usage

Allows basic access to a MySQL database.

This node uses the query operation against the configured database. This does allow both INSERTS and DELETES.

By its very nature it allows SQL injection... so be careful out there...

The msg.topic must hold the query for the database, and the result is returned in msg.payload.

Typically the returned payload will be an array of the result rows.

If nothing is found for the key then null is returned.

The reconnect retry timeout in milliseconds can be changed by adding a line to settings.js

mysqlReconnectTime: 30000,

The timezone can be set like GMT, EST5EDT, UTC, etc.

The charset defaults to the "old" Mysql 3 byte UTF. If you need support for emojis etc then use UTF8MB4.

Preparing Queries

msg.payload=[24, 'example-user'];
msg.topic="INSERT INTO users (`userid`, `username`) VALUES (?, ?);"
return msg;

with named parameters:

msg.payload={}
msg.payload.userToChange=42;
msg.payload.newUsername="example-user";
msg.topic="INSERT INTO users (`userid`, `username`) VALUES (:userToChange, :newUsername) ON DUPLICATE KEY UPDATE `username`=:newUsername;"
return msg;

Documentation

Documentation of the used Node.js package