Node-red-contrib-mysql2 node

i saw in nodered documentation there is an existing node node-red-contrib-mysql2 node where it is possible to get parameters from incomming msg
"We can also send the server details using msg.server, without adding those details at node level"

As the documentation is light on this topic i m unable to do it working. Can you clarify the syntax we should use?
i use the following one but not working

var test= {Host:mariadb_Host,Port:mariadb_Port, Username: mariadb_Username, Password: mariadb_Password, Database: 'myDatabase'}
newmsg.Server=test

yea the documentation is a bit limited on the node but if you go to Import (Ctrl+I) > Examples
you should see an example flow for node-red-contrib-mysql2

From their example msg.server should be :

{
"host":"chq05-w10-tst01.axcess-financial.com",
"port":3306,
"username":"username",
"password":"password",
"db":"robot"
}

js is case-sensitive so keep the properties as lowercase

it doesn't works. Seems the node doesn't use the IP provide as i get "connect ECONNREFUSED 127.0.0.1:3306"

below the code in function node

var newmsg={};
newmsg.Server={"host":"11.1.1.228","port":"3306", "username": "user", "password": "@L8S", "database": "test"}
//newmsg.Password=mariadb_Password;
newmsg.topic="select id,profileName from ProfileEntity;";
//node.log("------ GET ProfileEntity mysql(req)="+newmsg.topic);
node.warn(newmsg)
return newmsg;

i havent used the node but from the example
the database property should be db and not database
also you have used msg.Server with capital S. i believe it should be lowercase

var newmsg={};

newmsg.server={
"host":"11.1.1.228",
"port":"3306", 
"username": "user", 
"password": "@L8S", 
"db": "test"
}

//newmsg.Password=mariadb_Password;
newmsg.topic="select id,profileName from ProfileEntity;";
//node.log("------ GET ProfileEntity mysql(req)="+newmsg.topic);
node.warn(newmsg)
return newmsg;

good eyes !
you are right but still face the same problem
"connect ECONNREFUSED 127.0.0.1:3306"

var newmsg={};
newmsg.Server={"host":"11.1.1.228","port":"3306", "username": "user", "password": "@L8S", "db": "test"}
//newmsg.Password=mariadb_Password;
newmsg.topic="select id,profileName from ProfileEntity;";
//node.log("------ GET ProfileEntity mysql(req)="+newmsg.topic);
node.warn(newmsg)
return newmsg;

sorry i forget to change newmsg.Server to newmsg.server

With this change it works as expected. Thanks a lot to your good eyes

1 Like

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