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?