I am using node-red-node-mysql node to connect with mySQL database. I want to set my database credential (i.e. server name, db name, uid and password) from global variables.
Is there any way to do it?
I am using node-red-node-mysql node to connect with mySQL database. I want to set my database credential (i.e. server name, db name, uid and password) from global variables.
Is there any way to do it?
not at this point in time.
You can do the "next best thing" and just put the params in a function node, save it as a custom flow (of whatever the correct word is for it, my bad if I got the exact word wrong again), and use it to pass the params to another MySQL function (where you have your custom MySQL logic).
FYI, I do not use the mysql plugin ( node-red-node-mysql
) and write all my MySQL code in a function node (it is really simple anyway, some basics below) because it works much better, at least for me. This is especially true (again, for me, YMMV) because my MySQL configuration uses a socket for the MySQL port, and the mysql plugin only accepts an int as a port number (not a string where we can pass a unix socket as the port).
Example:
var mysql = global.get("mysql");
var connection = mysql.createConnection({
host: 'localhost',
user: 'my_cool_dbuser',
port: '/var/run/mysqld/mysqld.sock',
password: 'my_cool_password',
database: 'my_big_amazing_database'
});
etc etc
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.