# Problem to read data from Mysql

**URL:** https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387
**Category:** General
**Tags:** database
**Created:** [8 November 2021 15:57 UTC](https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387 "2021-11-08T15:57:31Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)
#### Post date: [8 November 2021 15:57 UTC](https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387/1 "2021-11-08T15:57:31Z")

</div>

Hello, I am trying to make a query to a mysql table filtering the data by the date that interests me at the time of the query, the connection and the query are created if errors but the msg has no data, the array appears empty when As seen in the image of the mysql table if there is data on that date,  
Any suggestions ?? Since I have tried many things and to no avail, I attach images since the flow is quite simple.

Image the dashboard

![R1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/2/02005f37eec11fc9ec5015c2a90d82b0f9fc3fe4.png)

Image the flow

 ![R2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/9/0936776aed429d652b3d57e3db7f212579f43c92.png)

Image the function node

 ![R2.1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/9/f9da4206086424e251620086e23cc92d2d4c2e8f.png)

mysql table image

 ![R4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/9/09cf76429b6904a25080d963dcb301f5130a7eef.png)

Debug

 ![R3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/e/cea4b81cf20488b6dc348c8db9a8346517eb830b.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: [8 November 2021 16:42 UTC](https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387/2 "2021-11-08T16:42:37Z")

</div>

What column type is the time field?

---

<div class="post-metadata">

### Author: ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)
#### Post date: [8 November 2021 16:52 UTC](https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387/3 "2021-11-08T16:52:38Z")

</div>

timestamp

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [8 November 2021 17:03 UTC](https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387/4 "2021-11-08T17:03:33Z")

</div>

Assuming a datatype of "Datetime":  
You need to wrap the dates in single quotes:  
`"select * from datos where tiempo between '2021-10-10' and '2021-10-22'"`

---

<div class="post-metadata">

### Author: ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)
#### Post date: [9 November 2021 10:22 UTC](https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387/5 "2021-11-09T10:22:25Z")

</div>

when I do it this way it gives me an error.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/b/1b9cd125497e4acea572a84e2a9f201072aa604b.png)

This is the console cmd error

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/b/2b680fec9762991c2e2e00e92e2f896c33703726.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: [9 November 2021 10:42 UTC](https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387/6 "2021-11-09T10:42:07Z")

</div>

Connect the sql node only to the debug node (remove any other wires) and see what happens.

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [9 November 2021 11:15 UTC](https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387/7 "2021-11-09T11:15:44Z")

</div>

There are several posts on the forum about Node-Red running out of memory, I've not seen the problem myself.

Is the database MySQL or Mariadb? (not sure if they are synonymous)  
What hardware and OS are they running on?  
Are you using Docker?  
What versions of Node-Red (from the hamburger menu), node.js (node -v) and database (mariadb --version) do you have?

---

<div class="post-metadata">

### Author: ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)
#### Post date: [9 November 2021 14:59 UTC](https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387/8 "2021-11-09T14:59:57Z")

</div>

> [@jbudd](#):
>
> '2021-10-10' and '2021-10-22'

The Data base is MYSQL, my hardware is a pc gaming asus and windows 10 and node red is the last version

---

<div class="post-metadata">

### Author: ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)
#### Post date: [9 November 2021 15:04 UTC](https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387/9 "2021-11-09T15:04:12Z")

</div>

It works,,

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/3/63ba48a85fcb98f346c5f78161f7af90f5fb437e.png)

now I would like the query of dates not to be fixed, that it could be consulted from the dashboard choosing the range of dates that you select for the query

that would be similar to what I had

msg.topic = "SELECT \* FROM data where TIME between" + start + "and" + end + ";";

but working of course is

---

<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: [9 November 2021 15:07 UTC](https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387/10 "2021-11-09T15:07:52Z")

</div>

> [@osancleca](#):
>
> It works,,

I thought it might. The problem was that you were sending 8 million values to the dashboard table. I am not surprised it gave it indigestion.

---

<div class="post-metadata">

### Author: ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)
#### Post date: [9 November 2021 15:43 UTC](https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387/11 "2021-11-09T15:43:28Z")

</div>

from what I understand with node red working with this volume of data is complicated, because I am trying to create a csv with those 8 thousand arrays and it exploits node red

---

<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: [9 November 2021 16:16 UTC](https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387/12 "2021-11-09T16:16:43Z")

</div>

> [@osancleca](#):
>
> 8 thousand

8 Million (8,000,000)

Creating a csv should be ok, but I think you were sending it to a dashboard table. How could you possibly scroll down through a table that long in the browser?

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [10 November 2021 14:40 UTC](https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387/13 "2021-11-10T14:40:35Z")

</div>

> [@osancleca](#):
>
> now I would like the query of dates not to be fixed, that it could be consulted from the dashboard choosing the range of dates that you select for the query
> 
> that would be similar to what I had
> 
> msg.topic = "SELECT \* FROM data where TIME between" + start + "and" + end + ";";

I think you just need to include the single quotes in your strings:  
msg.topic = "SELECT \* FROM data where TIME between '" + start + "' and '" + end + "' ;";

---

<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: [10 November 2021 16:14 UTC](https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387/14 "2021-11-10T16:14:49Z")

</div>

> [@jbudd](#):
>
> msg.topic = "SELECT \* FROM data where TIME between '" + start + "' and '" + end + "' ;";

I think examples like this are easier to write/read by using the template literal syntax

```auto
msg.topic = `SELECT * FROM data where TIME between '${start}' and '${end}';`

```

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [10 November 2021 16:45 UTC](https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387/15 "2021-11-10T16:45:23Z")

</div>

Thanks. I've never come across that syntax before.

---

<div class="post-metadata">

### Author: ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)
#### Post date: [10 November 2021 18:07 UTC](https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387/16 "2021-11-10T18:07:37Z")

</div>

it works well in both ways,

the problem now is to generate a cvs file with an array of objects which is the load format extracted from mysql, as you can see I have a little sequence below where I simulate an array of objects and it works fine as it only has 3 objects but when it i do with mysql node network payload explodes

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f6d1aa62800fb030f786ab58045e11e131b4cd88.png)

this is what happens when i try to pull the data out of mysql

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/9/9972c95a5da65c1490947d3a7b2d18be8cc138c3.png)

Although the connected mysql node appears in the image, it is not like that, it crashes and I have to restart it

---

<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: [10 November 2021 18:20 UTC](https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387/17 "2021-11-10T18:20:50Z")

</div>

> [@osancleca](#):
>
> it crashes and I have to restart it

It is no good just stating that. In what way does it crash? What is in the node red log? What is shown by the debug nodes?

---

<div class="post-metadata">

### Author: ![osancleca](https://avatars.discourse-cdn.com/v4/letter/o/ecccb3/32.png) [@osancleca](https://discourse.nodered.org/u/osancleca)
#### Post date: [10 November 2021 18:22 UTC](https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387/18 "2021-11-10T18:22:09Z")

</div>

I answer myself hahaha the node csv the only thing it does is separate by commas when I already get that from mysql, it seems that it works friends thanks for the help

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/b/6b11f7ca7cc4e6d2a0f2d87d2db5d31a7ac7a567.png)

---

<div class="post-metadata">

### Author: ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)
#### Post date: [10 November 2021 18:31 UTC](https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387/19 "2021-11-10T18:31:56Z")

</div>

It is possible to get MySQL to write a CSV file directly, which would presumably avoid huge amaounts of data crashing Node-Red.

An example from [https://www.databasestar.com/mysql-output-file/](https://www.databasestar.com/mysql-output-file/)

```auto
SELECT id, first_name, last_name
FROM customer
INTO OUTFILE '/temp/myoutput.txt'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';

```

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [9 January 2022 18:32 UTC](https://discourse.nodered.org/t/problem-to-read-data-from-mysql/53387/20 "2022-01-09T18:32:04Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
