# Setting Environment Variables in MySQL Node (Docker-Node-RED)

**URL:** <https://discourse.nodered.org/t/setting-environment-variables-in-mysql-node-docker-node-red/95831>\
**Category:** General\
**Tags:** docker, mysql\
**Created:** [6 March 2025 18:41 UTC](https://discourse.nodered.org/t/setting-environment-variables-in-mysql-node-docker-node-red/95831 "2025-03-06T18:41:48Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![vskbot007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vskbot007/32/76423_2.png) [@vskbot007](https://discourse.nodered.org/u/vskbot007)\
**Post date:** [6 March 2025 18:41 UTC](https://discourse.nodered.org/t/setting-environment-variables-in-mysql-node-docker-node-red/95831/1 "2025-03-06T18:41:48Z")

</div>

Hello Node-RED community,

I need some help with setting environment variables in the **MySQL database node** within a **Docker-based Node-RED setup**.

**What I’m Trying to Achieve**

I want to define my database connection details (host, user, password, database name, etc.) as **environment variables** in `docker-compose.yml` and reference them inside the MySQL configuration node.

Not sure if this is possible or the best approach, but if anyone has done this before **without modifying the MySQL node source code** , I’d love to hear your ideas!

Thanks in advance! 😊

---

<div class="post-metadata">

**Author:** ![omrid](https://avatars.discourse-cdn.com/v4/letter/o/77aa72/32.png) [@omrid](https://discourse.nodered.org/u/omrid)\
**Post date:** [6 March 2025 19:05 UTC](https://discourse.nodered.org/t/setting-environment-variables-in-mysql-node-docker-node-red/95831/2 "2025-03-06T19:05:01Z")

</div>

Assuming you configured your env variables for the docker, all you need to do is refer to them with `${...}`.  
for example, if you have an env var named **DB\_PORT** in the docker, just set `${DB_PORT}` in your node configuration and it will resolve automatically.

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [6 March 2025 19:57 UTC](https://discourse.nodered.org/t/setting-environment-variables-in-mysql-node-docker-node-red/95831/3 "2025-03-06T19:57:06Z")

</div>

~~Its currently not possible.~~  
~~The MysSQL Config Node (that is home to the credentials/server) requires static values - and cant be taken from variables.~~

~~Raise a Feature Request or put up a PR to add the ability~~

EDIT  
See below correction

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 March 2025 19:59 UTC](https://discourse.nodered.org/t/setting-environment-variables-in-mysql-node-docker-node-red/95831/4 "2025-03-06T19:59:47Z")

</div>

> [@marcus-j-davies](#):
>
> Its currently not possible.  
> The MysSQL Config Node (that is home to the credentials/server) requires static values

You can use the `${...}` syntax in any text box

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/d/5d3ead9c96c57a16e5578a8c9a09f5bd308af64e.png)

as stated here: [Using environment variables : Node-RED](https://nodered.org/docs/user-guide/environment-variables)

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [6 March 2025 20:02 UTC](https://discourse.nodered.org/t/setting-environment-variables-in-mysql-node-docker-node-red/95831/5 "2025-03-06T20:02:18Z")

</div>

Oh!!

Thanks for the correction @Steve-Mcl  
This has me wondering however - I don't see in the source, that there is any magic for this to happen in the Node itself.

So is this evaluated - before the Node its self is started?

I always thought the Node needs to support this?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 March 2025 20:04 UTC](https://discourse.nodered.org/t/setting-environment-variables-in-mysql-node-docker-node-red/95831/6 "2025-03-06T20:04:59Z")

</div>

> [@marcus-j-davies](#):
>
> So is this evaluated - before the Node its self is started?

Yes.

> [@marcus-j-davies](#):
>
> I always thought the Node needs to support this?

In truth, all nodes should be updated to use the TypedInput. The TypedInput permits the `$` dropdown which expands usability to allow things like `$` `192.168.1.${MY_NODE}:${MY_PORT}` where as the textbox version ONLY permits a single `${...}` var without interpolation

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [6 March 2025 20:07 UTC](https://discourse.nodered.org/t/setting-environment-variables-in-mysql-node-docker-node-red/95831/7 "2025-03-06T20:07:51Z")

</div>

Thanks.

I hereby stand corrected 🫣  
I have seen vars in text boxes - just always thought it needs to be implemented Node Side

---

<div class="post-metadata">

**Author:** ![vskbot007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vskbot007/32/76423_2.png) [@vskbot007](https://discourse.nodered.org/u/vskbot007)\
**Post date:** [7 March 2025 19:00 UTC](https://discourse.nodered.org/t/setting-environment-variables-in-mysql-node-docker-node-red/95831/8 "2025-03-07T19:00:27Z")

</div>

Yeah also this single env configuration would be easier to set and also flexible rather than setting different one's. I've seen this recently while playing around with redis .

---

<div class="post-metadata">

**Author:** ![vskbot007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vskbot007/32/76423_2.png) [@vskbot007](https://discourse.nodered.org/u/vskbot007)\
**Post date:** [7 March 2025 19:04 UTC](https://discourse.nodered.org/t/setting-environment-variables-in-mysql-node-docker-node-red/95831/9 "2025-03-07T19:04:32Z")

</div>

I'm still trying the solution i ended up with some docker issue will update once this works 🙂 .  
Also is there a way to set the password as well?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [7 March 2025 19:55 UTC](https://discourse.nodered.org/t/setting-environment-variables-in-mysql-node-docker-node-red/95831/10 "2025-03-07T19:55:48Z")

</div>

> [@vskbot007](#):
>
> Also is there a way to set the password as well?

It should obey the same rules.

---

<div class="post-metadata">

**Author:** ![vskbot007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vskbot007/32/76423_2.png) [@vskbot007](https://discourse.nodered.org/u/vskbot007)\
**Post date:** [25 March 2025 20:29 UTC](https://discourse.nodered.org/t/setting-environment-variables-in-mysql-node-docker-node-red/95831/11 "2025-03-25T20:29:05Z")

</div>

Hi, I finally tested it out. I replaced my old configuration with environment variables, keeping everything else the same. However, I'm now encountering a "Too many connections" error.

Any idea on what might be causing this?

 ![Screenshot from 2025-03-26 01-55-08](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/0/20bd73caf1e0850b0cb7bf67e67bb89b08335a70.png)  
 ![Screenshot from 2025-03-26 01-53-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/d/7d5ceadff30b95f1bb5d95e6ebce7ee6500d7834.png)

---

<div class="post-metadata">

**Author:** ![vskbot007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vskbot007/32/76423_2.png) [@vskbot007](https://discourse.nodered.org/u/vskbot007)\
**Post date:** [3 April 2025 20:47 UTC](https://discourse.nodered.org/t/setting-environment-variables-in-mysql-node-docker-node-red/95831/12 "2025-04-03T20:47:18Z")

</div>

@Steve-Mcl hi steve can you help me with this part. I'm not sure how to debug this . So i used the same config by setting things directly in the node and it was'nt giving any error but if i use the same config from env variables i'm getting too many connections error.

---

<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:** [3 April 2025 21:03 UTC](https://discourse.nodered.org/t/setting-environment-variables-in-mysql-node-docker-node-red/95831/13 "2025-04-03T21:03:33Z")

</div>

Do you mean that if you change the node configuration to a literal value, and make no other changes, that the error goes away?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [3 April 2025 21:41 UTC](https://discourse.nodered.org/t/setting-environment-variables-in-mysql-node-docker-node-red/95831/14 "2025-04-03T21:41:19Z")

</div>

How many database nodes do you have?

Are you using subflows (with database nodes in)

---

<div class="post-metadata">

**Author:** ![vskbot007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vskbot007/32/76423_2.png) [@vskbot007](https://discourse.nodered.org/u/vskbot007)\
**Post date:** [4 April 2025 03:53 UTC](https://discourse.nodered.org/t/setting-environment-variables-in-mysql-node-docker-node-red/95831/15 "2025-04-04T03:53:58Z")

</div>

Yes the error goes away if i add the config directly in the node itself

---

<div class="post-metadata">

**Author:** ![vskbot007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vskbot007/32/76423_2.png) [@vskbot007](https://discourse.nodered.org/u/vskbot007)\
**Post date:** [4 April 2025 03:55 UTC](https://discourse.nodered.org/t/setting-environment-variables-in-mysql-node-docker-node-red/95831/16 "2025-04-04T03:55:35Z")

</div>

i have around 150 nodes and all of them are in subflows

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 April 2025 07:02 UTC](https://discourse.nodered.org/t/setting-environment-variables-in-mysql-node-docker-node-red/95831/17 "2025-04-04T07:02:28Z")

</div>

Would you be willing to share your complete flows so I can investigate your issue?

I don't need any of your connection details or private secrets, just a full expert of your flows.

If you'd rather not share them publicly, then you can DM me.

---

<div class="post-metadata">

**Author:** ![vskbot007](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/vskbot007/32/76423_2.png) [@vskbot007](https://discourse.nodered.org/u/vskbot007)\
**Post date:** [9 April 2025 04:18 UTC](https://discourse.nodered.org/t/setting-environment-variables-in-mysql-node-docker-node-red/95831/18 "2025-04-09T04:18:12Z")

</div>

Hi @Steve-Mcl good news—everything’s working as expected now!

I restarted both Node-RED and my database, and since then, things have been running smoothly. I’ve been doing some testing over the past few days to see if anything breaks, and so far, so good.

I’ll keep you posted if I run into any issues.

Also, a big thanks to you and everyone else who’s been helping me out with this—really appreciate it! 😊
