# MySql Node "Error: Pool Is closed"

**URL:** https://discourse.nodered.org/t/mysql-node-error-pool-is-closed/56556
**Category:** General
**Created:** [13 January 2022 01:42 UTC](https://discourse.nodered.org/t/mysql-node-error-pool-is-closed/56556 "2022-01-13T01:42:49Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![saxenaramesh](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@saxenaramesh](https://discourse.nodered.org/u/saxenaramesh)
#### Post date: [13 January 2022 01:42 UTC](https://discourse.nodered.org/t/mysql-node-error-pool-is-closed/56556/1 "2022-01-13T01:42:49Z")

</div>

Dear Friends,  
Believe me, I have done extensive search for this issue on node-red forum and other possible sites suggested by google. Somehow, I am not able to fix it.  
I am using mysql node quite frequently. For one of my project, spread across 5 flows, it has been used around 43 times for access to same Mysql Database with same credentials. I need to have various queries for my dashboards. It was working quite well for about a month.  
Now, I am facing an issue. I very frequently get error for mysql node : "Error: Pool is closed". I have following questions:

1. How can I possible fix this issue?
2. Is this issue because of using mysql node too many times?

Please help on this issue.

my flow example is as below:

```auto
[{"id":"48d3532b.b9f87c","type":"function","z":"7496a53c.c9e7dc","name":"","func":"var d = new Date()\nvar z = d.getFullYear()+'-'+(d.getMonth()+1)+'-'+(d.getDate()-1);\nvar t1 = 0 + \":\" + 0 + \":\" + 0;\nvar t2 = 23 + \":\" + 59 + \":\" + 59;\nvar a = z+' '+t1;\nvar b = z+' '+t2;\nmsg.topic = 'select M1_KVAH as grid_cons from em1_live_values where time_stamp between \"'+a+'\" and \"'+b+'\" and M1_KVAH > 0 order by time_stamp desc limit 1';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":1740,"wires":[["5a1ba33f.40c04c"]]},{"id":"8d85ff65.ae86e","type":"function","z":"7496a53c.c9e7dc","name":"","func":"var str = msg.payload;\nstr = str[0]['grid_cons'];\nmsg.payload = str;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":1740,"wires":[["c1a1083e.0bcf28"]]},{"id":"5a1ba33f.40c04c","type":"mysql","z":"7496a53c.c9e7dc","mydb":"18593ab4.649a45","name":"Query","x":510,"y":1740,"wires":[["8d85ff65.ae86e"]]},{"id":"a649c8e4.09b4f8","type":"function","z":"7496a53c.c9e7dc","name":"","func":"var d = new Date()\nvar z = d.getFullYear()+'-'+(d.getMonth()+1)+'-'+(d.getDate()-1);\nvar t1 = 0 + \":\" + 0 + \":\" + 0;\nvar t2 = 23 + \":\" + 59 + \":\" + 59;\nvar a = z+' '+t1;\nvar b = z+' '+t2;\nmsg.topic = 'select M1_KVAH from em1_live_values where time_stamp between \"'+a+'\" and \"'+b+'\" and M1_KVAH > 0 order by time_stamp limit 1';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":340,"y":1800,"wires":[["cee9dc66.e9f98"]]},{"id":"65920934.1aa7c8","type":"function","z":"7496a53c.c9e7dc","name":"","func":"var str = msg.payload;\nstr = str[0]['M1_KVAH'];\nmsg.payload = str;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":1800,"wires":[["c1a1083e.0bcf28"]]},{"id":"cee9dc66.e9f98","type":"mysql","z":"7496a53c.c9e7dc","mydb":"18593ab4.649a45","name":"query2","x":490,"y":1800,"wires":[["65920934.1aa7c8"]]},{"id":"96d99e31.f8f5e","type":"inject","z":"7496a53c.c9e7dc","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":150,"y":1740,"wires":[["48d3532b.b9f87c","a649c8e4.09b4f8"]]},{"id":"c1a1083e.0bcf28","type":"debug","z":"7496a53c.c9e7dc","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":910,"y":1760,"wires":[]},{"id":"18593ab4.649a45","type":"MySQLdatabase","name":"","host":"127.0.0.1","port":"3306","db":"Aditya_EMS","tz":"+05:30","charset":"UTF8"}]

```

---

<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: [13 January 2022 01:44 UTC](https://discourse.nodered.org/t/mysql-node-error-pool-is-closed/56556/2 "2022-01-13T01:44:52Z")

</div>

Did you search the forum for that error msg? I found several hits. Do any of them help?

---

<div class="post-metadata">

### Author: ![saxenaramesh](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@saxenaramesh](https://discourse.nodered.org/u/saxenaramesh)
#### Post date: [13 January 2022 01:53 UTC](https://discourse.nodered.org/t/mysql-node-error-pool-is-closed/56556/3 "2022-01-13T01:53:47Z")

</div>

Yes, I actually did search with exact same error message. There are quite a few topics, but goes in various directions. I could not find anything which can solve my issue.

---

<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: [13 January 2022 02:06 UTC](https://discourse.nodered.org/t/mysql-node-error-pool-is-closed/56556/4 "2022-01-13T02:06:51Z")

</div>

1. what version of Node-RED and node.js are you running (you can get this from the startup log)
2. What hardware and OS are you using?
3. How many occurances of `mysql` node do you have in all?
4. Have you tried reducing the number of occurances of the node?

---

<div class="post-metadata">

### Author: ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)
#### Post date: [13 January 2022 08:14 UTC](https://discourse.nodered.org/t/mysql-node-error-pool-is-closed/56556/5 "2022-01-13T08:14:26Z")

</div>

I had a similar error when using the MySQL node last year (2021).

> [@\[Feedback wanted\] Update to mysql node](https://discourse.nodered.org/t/feedback-wanted-update-to-mysql-node/53936):
>
> I have just updated the node-red-node-mysql node to use the more maintained mysql2 library in response to [MySQL 8.0 needs new Auth mechanism · Issue #853 · node-red/node-red-nodes · GitHub](https://github.com/node-red/node-red-nodes/issues/853) - and it is on npm as node-red-node-mysql@next so can be manually installed... eg cd ~/.node-red && npm i node-red-node-mysql@next If anyone has any time to give it a whirl I would really appreciate it. It claims to be nearly compatible with the basic mysql library but there are some known differences, see-…

Are you using the latest version as @dceejay has done a lot of work improving this node, in fact there was an update a week ago.

 ![Screen Shot 01-13-22 at 08.07 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/3/a3a1b8901598014427c51d62d64cf3c907db5e99.gif)  
One of my problems was the number of dB connections. I found when I reduced the number of connections the node behaved much better.

I'm also using this flow to perform a 'keep database alive' every 15-minutes.

> [@\[Feedback wanted\] Update to mysql node](https://discourse.nodered.org/t/feedback-wanted-update-to-mysql-node/53936/4):
>
> Upgrade MySQL - working like it suppose to.

---

<div class="post-metadata">

### Author: ![saxenaramesh](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@saxenaramesh](https://discourse.nodered.org/u/saxenaramesh)
#### Post date: [14 January 2022 15:58 UTC](https://discourse.nodered.org/t/mysql-node-error-pool-is-closed/56556/6 "2022-01-14T15:58:35Z")

</div>

Thanks for your reply.

1. I am using Node red - 1.3.5. & Node.js - 14.18.1
2. I am using Raspberry Pi & Raspbian OS
3. I have 43 mysql node occurances.
4. I tried to the best of my knowledge, still trying actually.

---

<div class="post-metadata">

### Author: ![saxenaramesh](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@saxenaramesh](https://discourse.nodered.org/u/saxenaramesh)
#### Post date: [14 January 2022 16:10 UTC](https://discourse.nodered.org/t/mysql-node-error-pool-is-closed/56556/7 "2022-01-14T16:10:18Z")

</div>

Hello Zenofmud,

Reducing the number of nodes using mysql is helping. The occurence frequency of "Error: Pool is closed" is reducing. I am wondering if we really need lot of nodes, will it help to use a different mysql schema design. for example:  
INSTEAD of,  
approach 1: db1 : Table1, Table2, Table3, Table4, Table5  
WILL IT HELP TO USE BELOW,  
approach 2: db1: Table 1, Table 2,  
db2: Table 3, Table 4,  
db3: Table 5.  
So we will connect to different DBs rather connecting to same DB many times. this may be a substantial work to implement this, what is your opinion, will it improve the situation?

---

<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 January 2022 16:44 UTC](https://discourse.nodered.org/t/mysql-node-error-pool-is-closed/56556/8 "2022-01-14T16:44:07Z")

</div>

I can't really say if splitting tables into different databases will help. I would be examining if you could have multiple queries pass thru the same mysql node. You could add an extra item to the msg benig passed - like msg.table - then look at the msg coming out of the mysql node and test msg.table to determine where the data should go.

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [14 January 2022 19:19 UTC](https://discourse.nodered.org/t/mysql-node-error-pool-is-closed/56556/9 "2022-01-14T19:19:30Z")

</div>

Which version of the MySQL node are you using ?

---

<div class="post-metadata">

### Author: ![saxenaramesh](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@saxenaramesh](https://discourse.nodered.org/u/saxenaramesh)
#### Post date: [15 January 2022 03:46 UTC](https://discourse.nodered.org/t/mysql-node-error-pool-is-closed/56556/10 "2022-01-15T03:46:20Z")

</div>

Hello, Currently its is 0.2.1. I know there is an update available to 1.0.0. I will try to update it. Is there anything specific enhancement done during 1.0.0 for this particular error?

---

<div class="post-metadata">

### Author: ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)
#### Post date: [15 January 2022 08:31 UTC](https://discourse.nodered.org/t/mysql-node-error-pool-is-closed/56556/11 "2022-01-15T08:31:02Z")

</div>

Yes there were several fixes around the pooling and memory leaks

---

<div class="post-metadata">

### Author: ![saxenaramesh](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@saxenaramesh](https://discourse.nodered.org/u/saxenaramesh)
#### Post date: [15 January 2022 10:58 UTC](https://discourse.nodered.org/t/mysql-node-error-pool-is-closed/56556/12 "2022-01-15T10:58:55Z")

</div>

Thanks for the reply. I will upgrade to latest version of mysql node and give you feedback.

---

<div class="post-metadata">

### Author: ![rakgupta](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rakgupta/32/42535_2.png) [@rakgupta](https://discourse.nodered.org/u/rakgupta)
#### Post date: [25 January 2022 00:59 UTC](https://discourse.nodered.org/t/mysql-node-error-pool-is-closed/56556/13 "2022-01-25T00:59:43Z")

</div>

> [@saxenaramesh](#):
>
> I will upgrade to latest version of mysql node and give you feedback.

I am seeing the same thing with mySQL node v1.0.0. Were you able to solve this issue? I have 2 instances of Node-RED running (on different machines). I am not seeing this issue on the instance with mySQL node v 0.1.9. Both instances are connected to the same database.

UPDATE: Stopping and restarting Node-RED seems to have fixed it 🤷🏽‍♂️

---

<div class="post-metadata">

### Author: ![saxenaramesh](https://avatars.discourse-cdn.com/v4/letter/s/919ad9/32.png) [@saxenaramesh](https://discourse.nodered.org/u/saxenaramesh)
#### Post date: [2 February 2022 17:52 UTC](https://discourse.nodered.org/t/mysql-node-error-pool-is-closed/56556/14 "2022-02-02T17:52:02Z")

</div>

Hello, I have reduced the numbers of mysql nodes used by combining multiple queries and then using the data as per requirement. This is working fine now.

---

<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: [3 April 2022 17:52 UTC](https://discourse.nodered.org/t/mysql-node-error-pool-is-closed/56556/15 "2022-04-03T17:52:09Z")

</div>

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