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

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! :blush:

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.

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

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

as stated here: Using environment variables : Node-RED

2 Likes

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?

Yes.

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

1 Like

Thanks.

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

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 .

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

It should obey the same rules.

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?


@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.

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

How many database nodes do you have?

Are you using subflows (with database nodes in)

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

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

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.

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! :blush:

1 Like