How to Use Node-Red wit MySQL Example
Using MySQL with Node-RED
Copy JSON
Note: some third-party nodes may appear with blank styling, and not as they appear in the Node-RED Editor.
Copy [{"id":"8145e77bde5dc885","type":"inject","z":"8ceec3b60749ea40","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":260,"wires":[["dcbe52fbd76e9f5f"]]},{"id":"dcbe52fbd76e9f5f","type":"function","z":"8ceec3b60749ea40","name":"Create Table","func":"msg.topic= \"CREATE TABLE iot_factory (id SERIAL PRIMARY KEY, device_id VARCHAR(50) NOT NULL, timestamp TIMESTAMP NOT NULL, temperature FLOAT, humidity FLOAT, pressure FLOAT, status VARCHAR(20));\"\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":260,"wires":[["28096233281177f6"]]},{"id":"4b3f6e61046e4855","type":"debug","z":"8ceec3b60749ea40","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":260,"wires":[]},{"id":"79c6b7e2bc7f8615","type":"inject","z":"8ceec3b60749ea40","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":340,"wires":[["c66308eb7e9ce199"]]},{"id":"c66308eb7e9ce199","type":"function","z":"8ceec3b60749ea40","name":"Insert","func":"msg.topic= \"INSERT INTO iot_factory (device_id, timestamp, temperature, humidity, pressure, status) VALUES ('ABC123', NOW(), RAND() * 100, RAND() * 100, RAND() * 2000, 'OK');\"\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":340,"wires":[["af57c0ebf9ed4c95"]]},{"id":"c56fdf4a051d0e6b","type":"debug","z":"8ceec3b60749ea40","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":340,"wires":[]},{"id":"355a79275d6a9b1a","type":"inject","z":"8ceec3b60749ea40","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":440,"wires":[["1e3b6127a1a36218"]]},{"id":"1e3b6127a1a36218","type":"function","z":"8ceec3b60749ea40","name":"SelectAll","func":"msg.topic= \"SELECT *From iot_factory;\"\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":440,"wires":[["f7ce0803f92621a7"]]},{"id":"f90c532ce825d2d5","type":"debug","z":"8ceec3b60749ea40","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":800,"y":440,"wires":[]},{"id":"28096233281177f6","type":"mysql","z":"8ceec3b60749ea40","mydb":"03a85ce256ca9d57","name":"","x":580,"y":260,"wires":[["4b3f6e61046e4855"]]},{"id":"af57c0ebf9ed4c95","type":"mysql","z":"8ceec3b60749ea40","mydb":"03a85ce256ca9d57","name":"","x":580,"y":340,"wires":[["c56fdf4a051d0e6b"]]},{"id":"f7ce0803f92621a7","type":"mysql","z":"8ceec3b60749ea40","mydb":"03a85ce256ca9d57","name":"","x":580,"y":440,"wires":[["f90c532ce825d2d5"]]},{"id":"03a85ce256ca9d57","type":"MySQLdatabase","name":"MySQL Server","host":"127.0.0.1","port":"3306","db":"iot_data","tz":"","charset":"UTF8"}]