# Read from mysql db

**URL:** <https://discourse.nodered.org/t/read-from-mysql-db/2340>\
**Category:** Dashboard\
**Created:** [16 August 2018 12:49 UTC](https://discourse.nodered.org/t/read-from-mysql-db/2340 "2018-08-16T12:49:25Z")\
**Posts on this page:** 20\
**Page:** 2

<div class="post-metadata">

**Author:** ![Tefita](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@Tefita](https://discourse.nodered.org/u/Tefita)\
**Post date:** [13 November 2018 21:13 UTC](https://discourse.nodered.org/t/read-from-mysql-db/2340/22 "2018-11-13T21:13:33Z")

</div>

Colin, Thanks for the help; here is the capture:

 ![cap7](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/00888e93dcde39d212f1d4c33e3ec1b84f611fd3.png)

---

<div class="post-metadata">

**Author:** ![Tefita](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@Tefita](https://discourse.nodered.org/u/Tefita)\
**Post date:** [13 November 2018 21:16 UTC](https://discourse.nodered.org/t/read-from-mysql-db/2340/23 "2018-11-13T21:16:32Z")

</div>

Also this I have configured in each node:

![cap8](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/bb64b104f6780bfb34b2b16df15a50feb6c508b1.png)  
 ![captura9](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/7/73ebaedb30fa6bc00093fa74c54899103c6d90fa.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [13 November 2018 21:36 UTC](https://discourse.nodered.org/t/read-from-mysql-db/2340/24 "2018-11-13T21:36:05Z")

</div>

I don't see the output of the join node there.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [14 November 2018 00:00 UTC](https://discourse.nodered.org/t/read-from-mysql-db/2340/25 "2018-11-14T00:00:58Z")

</div>

@Tefita - in the join node, set the "Send the message -\> After a number of message parts" to `2`. As it is, you are only sending one value thru and it is in msg.payload. when you put in the `2` you should see th key:value pairs showing up. not msg.payload.temp\_amp

---

<div class="post-metadata">

**Author:** ![Tefita](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@Tefita](https://discourse.nodered.org/u/Tefita)\
**Post date:** [14 November 2018 02:05 UTC](https://discourse.nodered.org/t/read-from-mysql-db/2340/26 "2018-11-14T02:05:24Z")

</div>

Thank you for answering my questions, but I still have problems, do not know if I should change something in the node template?

![image3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6c7f55172c5fc07ab99da53b1e0157c73a21362f.png)  
 ![image2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/20303e8c98b068e4c502a8084ee97e0d8d9bddf9.png)

---

<div class="post-metadata">

**Author:** ![Tefita](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@Tefita](https://discourse.nodered.org/u/Tefita)\
**Post date:** [14 November 2018 02:11 UTC](https://discourse.nodered.org/t/read-from-mysql-db/2340/27 "2018-11-14T02:11:02Z")

</div>

Colin, place the node debug on all the nodes, and send no more information than the capture.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [14 November 2018 07:18 UTC](https://discourse.nodered.org/t/read-from-mysql-db/2340/28 "2018-11-14T07:18:32Z")

</div>

Please attach an export of your flow

---

<div class="post-metadata">

**Author:** ![Tefita](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@Tefita](https://discourse.nodered.org/u/Tefita)\
**Post date:** [14 November 2018 15:46 UTC](https://discourse.nodered.org/t/read-from-mysql-db/2340/29 "2018-11-14T15:46:28Z")

</div>

Thanks for your help, here is the flow

```auto
[{"id":"9f5049ab.a43a98","type":"mqtt in","z":"284cd45c.6a8e2c","name":"","topic":"prueba1/temp_amb","qos":"0","broker":"478ceb99.2c8d94","x":328,"y":306.9895658493042,"wires":[["4a052a03.7d37c4"]]},{"id":"80161886.658e18","type":"mqtt in","z":"284cd45c.6a8e2c","name":"","topic":"prueba1/temp_corp","qos":"0","broker":"478ceb99.2c8d94","x":317,"y":420.98956871032715,"wires":[["4a052a03.7d37c4"]]},{"id":"d08e3627.a84018","type":"debug","z":"284cd45c.6a8e2c","name":"debug_mysql","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1081.0001831054688,"y":250.9896068572998,"wires":[]},{"id":"4a052a03.7d37c4","type":"join","z":"284cd45c.6a8e2c","name":"Datos","mode":"custom","build":"object","property":"topic","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":514.0000953674316,"y":366.9896306991577,"wires":[["80775f4c.4f899","6b20ebde.333334"]]},{"id":"855df027.87953","type":"mysql","z":"284cd45c.6a8e2c","mydb":"8df20f66.9d9a3","name":"","x":877.1285095214844,"y":245,"wires":[["d08e3627.a84018"]]},{"id":"6b20ebde.333334","type":"template","z":"284cd45c.6a8e2c","name":"Datos_BD","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"INSERT INTO dispositivo2 (temp_amb, temp_corp)\nVALUES ({{payload.temp_amb}}, {{payload.temp_corp}});\n","output":"str","x":678.1666870117188,"y":277.3229808807373,"wires":[["855df027.87953","836a9322.9998f"]]},{"id":"80775f4c.4f899","type":"debug","z":"284cd45c.6a8e2c","name":"debug_nodo_join","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":694.1666717529297,"y":433.9895601272583,"wires":[]},{"id":"836a9322.9998f","type":"debug","z":"284cd45c.6a8e2c","name":"debug_nodo_template","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":905.1666793823242,"y":344.9895782470703,"wires":[]},{"id":"478ceb99.2c8d94","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"NodeRedSQLClient","usetls":false,"compatmode":true,"keepalive":"15","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""},{"id":"8df20f66.9d9a3","type":"MySQLdatabase","z":"","host":"127.0.0.1","port":"3306","db":"dispositivo2","tz":""}]

```

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [14 November 2018 15:56 UTC](https://discourse.nodered.org/t/read-from-mysql-db/2340/30 "2018-11-14T15:56:29Z")

</div>

please read this post and then edit your post above [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![Tefita](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@Tefita](https://discourse.nodered.org/u/Tefita)\
**Post date:** [14 November 2018 16:03 UTC](https://discourse.nodered.org/t/read-from-mysql-db/2340/31 "2018-11-14T16:03:58Z")

</div>

Oh thanks the correction, I hope the flow is fine

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [14 November 2018 17:01 UTC](https://discourse.nodered.org/t/read-from-mysql-db/2340/32 "2018-11-14T17:01:07Z")

</div>

In your template node you have

```auto
INSERT INTO dispositivo2 (temp_amb, temp_corp)
VALUES ({{payload.temp_amb}}, {{payload.temp_corp}});

```

so when and where are msg.payload.temp\_amp and msg.payload.temp\_corp being created? (HINT: You might want to change the debug node's so they display the complete msg object)

---

<div class="post-metadata">

**Author:** ![Tefita](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@Tefita](https://discourse.nodered.org/u/Tefita)\
**Post date:** [14 November 2018 17:21 UTC](https://discourse.nodered.org/t/read-from-mysql-db/2340/33 "2018-11-14T17:21:21Z")

</div>

I made the given suggestion and the changes were made, but then I must change the template node to another node, to get the insertion in the database

Thanks for the help

 ![f1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/fe0e030c48e91384f80e80523712b36017f1d4df.png)  
 ![f2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/d4da06897f0ef83c9d1774d9d479c5fe0add7895.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 November 2018 17:46 UTC](https://discourse.nodered.org/t/read-from-mysql-db/2340/34 "2018-11-14T17:46:49Z")

</div>

You have the Join node set to Combine each msg.topic. It should be combine each msg.payload using topic as the key. Change that then look at the output of the join node again particularly what is in the payload to see what you have to put in the template.

---

<div class="post-metadata">

**Author:** ![Tefita](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@Tefita](https://discourse.nodered.org/u/Tefita)\
**Post date:** [15 November 2018 06:08 UTC](https://discourse.nodered.org/t/read-from-mysql-db/2340/35 "2018-11-15T06:08:50Z")

</div>

At the exit of the join node I get the following message, where it is a "payload",  
 ![C2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/d4207f52f2acabe7b51903ddf82435c4d6be763e.png)

I have not really realized where my fault is, in the template flow I have configured it in this way:

```auto
INSERT INTO dispositivo2 (temp_amb, temp_corp)
VALUES ({{payload.temp_amb}}, {{payload.temp_corp}});

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [15 November 2018 07:00 UTC](https://discourse.nodered.org/t/read-from-mysql-db/2340/36 "2018-11-15T07:00:22Z")

</div>

You have not corrected the join node as I said. You need to change it to combine each msg.psyload.

---

<div class="post-metadata">

**Author:** ![Tefita](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@Tefita](https://discourse.nodered.org/u/Tefita)\
**Post date:** [15 November 2018 15:44 UTC](https://discourse.nodered.org/t/read-from-mysql-db/2340/37 "2018-11-15T15:44:59Z")

</div>

is true, I did not understand correctly what I should do, but now I have this in debug:  
 ![p1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/4cac6d8ec9644c6237f114bbb6cf9b0a23139bbf.png)  
 ![p2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/9a5411ad2817a96a445b580bacace4ac82041e4a.png)

I still can not understand how that payload: object, insert it in a database

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [15 November 2018 15:59 UTC](https://discourse.nodered.org/t/read-from-mysql-db/2340/38 "2018-11-15T15:59:37Z")

</div>

You can access the two variables using `msg.payload["prueba1/temp_amb"]` and similarly for the other one. You have to use the [...] because of the /. If you wrote `msg.payload.prueba1/temp_amb` it would think you meant `msg.payload.prueba1` divided by `temp_amb`.

If you hover with the mouse over the value in the debug pane then is shows some little square buttons. One of those will say Path Copied if you click it which means it will have copied to the paste buffer the path in the message to that value, which you can then paste in somewhere. That saves having to work out how what it is. Try it and you will see what I mean.

[Edit] I have made a correction above, forgot the quotes in the square brackets.

---

<div class="post-metadata">

**Author:** ![Tefita](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@Tefita](https://discourse.nodered.org/u/Tefita)\
**Post date:** [15 November 2018 16:16 UTC](https://discourse.nodered.org/t/read-from-mysql-db/2340/39 "2018-11-15T16:16:56Z")

</div>

Thanks Colin, I am not very clear about, I must change this / by "[...]"

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [15 November 2018 16:31 UTC](https://discourse.nodered.org/t/read-from-mysql-db/2340/40 "2018-11-15T16:31:45Z")

</div>

> [@Tefita](#):
>
> Thanks Colin, I am not very clear about, I must change this / by "[...]"

There is only so much I can do without actually developing your whole app for you. You want to get those values into your template, I have told you how to access them.

---

<div class="post-metadata">

**Author:** ![Tefita](https://avatars.discourse-cdn.com/v4/letter/t/a8b319/32.png) [@Tefita](https://discourse.nodered.org/u/Tefita)\
**Post date:** [15 November 2018 16:34 UTC](https://discourse.nodered.org/t/read-from-mysql-db/2340/41 "2018-11-15T16:34:07Z")

</div>

Thanks Colin, but I still have a problem in the node template

[Previous page](https://discourse.nodered.org/t/read-from-mysql-db/2340.md?page=1)

[Next page](https://discourse.nodered.org/t/read-from-mysql-db/2340.md?page=3)
