node-red-node-mysql does not connect

2,636 views
Skip to first unread message

Ross Newby

unread,
Sep 7, 2017, 8:42:32 AM9/7/17
to Node-RED
Hi, I'm simply trying to execute a select * statement on a mysql database using node-red-node-mysql but it results in the error 'database not connected'. I'm using the same credentials as a successful connection in java, so I cant see the issue

Host: 127.0.0.1 (as mySQL is running on my local machine)
Port: 3306
User: root
Password: password (correct password for mysql root user)
Database: eisquality (definitely the correct DB name)
Timezone: _ (i don't write anything here)

The above details are all in a 'mysql' node, can anyone point me in the right direction? Has anyone had trouble using the mysql node and a DB on their local machine? Thanks!

Zenofmud

unread,
Sep 7, 2017, 10:22:17 AM9/7/17
to node...@googlegroups.com
I just ran a test and it works fine for me. 

Are you sure your MySQL process is running? Do you have a local copy of phpMyAdmin installed so you can test the connection?

Paul
--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/2ef3cd24-3d12-48f6-affa-c3133c30a3ce%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Zenofmud

unread,
Sep 7, 2017, 10:23:47 AM9/7/17
to node...@googlegroups.com
Also, what is the exact syntax of your sql statement and where are you passing it?
A copy of the flow mould also be helpful

Ross Newby

unread,
Sep 7, 2017, 12:38:11 PM9/7/17
to Node-RED
I've attached a print screen of my flow, where my function block sets the msg topic as follows:
var newMsg = { payload: msg.payload };
newMsg.topic="select * from erroneousassets";
return newMsg;
but I've also tried even simpler:
msg.topic = "select * from erroneousassets";
return msg;
eisflow.PNG

Zenofmud

unread,
Sep 7, 2017, 12:44:09 PM9/7/17
to node...@googlegroups.com
Are you sure your MySQL process is running? Do you have a local copy of phpMyAdmin installed so you can test the connection?
--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

For more options, visit https://groups.google.com/d/optout.
<eisflow.PNG>

Ross Newby

unread,
Sep 7, 2017, 12:47:23 PM9/7/17
to Node-RED
MySQL is running as I open the command line client, you'll have to forgive me as I'm new to using SQL in javascript (I've only ever completed small Java projects with sql connections). 

Colin Law

unread,
Sep 7, 2017, 12:56:01 PM9/7/17
to node...@googlegroups.com
On 7 September 2017 at 13:42, Ross Newby <rossd...@gmail.com> wrote:
> Hi, I'm simply trying to execute a select * statement on a mysql database
> using node-red-node-mysql but it results in the error 'database not
> connected'. I'm using the same credentials as a successful connection in
> java, so I cant see the issue

Where are you seeing the error? In the screenshot you post in a later
post it is showing connected.

Colin

Ross Newby

unread,
Sep 7, 2017, 12:57:43 PM9/7/17
to Node-RED
Ahh yes, ther error is in the debug tab itself, which is strange that it says connected on the node itself (attahched)
eis error.PNG

Ross Newby

unread,
Sep 7, 2017, 1:29:07 PM9/7/17
to Node-RED
So it turns out, I get the error message 'Database not Connected' when I use an input node with 'inject once at start' selected but no other input. I've attached an example; when only the 'Once at Dashboard Launch' is attached, the error happens, but when the 'When Clicked' node is attached, it works! Its extremely strange, maybe the very first inject on launch is too soon to have started the database connection.

If anyone has experienced this or similar and has a solve, it would be much appreciated, as it's going to lead to a cluttered and rather illogical flow to workaround
eis working.PNG

Zenofmud

unread,
Sep 7, 2017, 1:32:03 PM9/7/17
to node...@googlegroups.com
What if you add a delay node after the inject - set it for a few seconds

-- 
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
--- 
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

For more options, visit https://groups.google.com/d/optout.
<eis working.PNG>

Ross Newby

unread,
Sep 7, 2017, 5:59:12 PM9/7/17
to Node-RED
Exactly what I've done and fixes the problem! Thanks for the help!

Colin Law

unread,
Sep 8, 2017, 3:14:04 AM9/8/17
to node...@googlegroups.com
It might be worth filing an issue with the node developers for this.
Arguably the node should take a little time to try and connect before
trying to run queries.

Colin
> https://groups.google.com/d/msgid/node-red/42401699-62c7-419d-a56b-e908825d6014%40googlegroups.com.

Nick O'Leary

unread,
Sep 8, 2017, 3:18:22 AM9/8/17
to Node-RED Mailing List
An issue has already been raised - but I'm not sure there's much we'll do about it.

The simple problem is passing a message to the node when it isn't connected and what should the node do in that scenario. It isn't unique to startup - any node that establishes a connection to a remote system might lose that connection at any time and have to reconnect. A flow that assumes a node is connected 100% of the time is exposed to problems when the node isn't connected.

The Status node can be used to trigger flows when states change. Rather than Inject on startup, it may be better to use the Status node to trigger a flow when the mysql node connects.

Nick


> To post to this group, send email to node...@googlegroups.com.
> Visit this group at https://groups.google.com/group/node-red.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/node-red/42401699-62c7-419d-a56b-e908825d6014%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.
--
http://nodered.org

Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send an email to node...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages