2 Replies Latest reply on Mar 30, 2015 3:00 PM by jchozas

    Intel Edison - Connect to SQL via NodeJS


      Hi all,


      I have installed mariadb from AlexT_Intel repository via opkg in the Intel Edison + breakboard Arduino and I can connect with Myql without problem.


      The database and table which I want to connect alrealdy exists:


      root@edison:~/PFM_2015# opkg list-installed | grep maria

      mariadb-client - 5.5.40-r0

      mariadb-server - 5.5.40-r0



      root@edison:~/PFM_2015# mysql -u root -p sensordatabase

      Enter password:

      Reading table information for completion of table and column names

      You can turn off this feature to get a quicker startup with -A


      Welcome to the MariaDB monitor.  Commands end with ; or \g.

      Your MariaDB connection id is 3

      Server version: 5.5.40-MariaDB Source distribution


      Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.


      Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


      MariaDB [sensordatabase]> show tables;


      | Tables_in_sensordatabase |


      | sensortable              |


      1 row in set (0.00 sec)


      MariaDB [sensordatabase]>



      The issue is that I want to connect with the database with node.js so I have installed the node-mysql package from felixge/node-mysql · GitHub (npm install mysql). The problem is that I get connection error but I had tried to do the same thing in Ubuntu I it worked perfectly so I do not know if can be an issue of yocto linux ,  I have used this package becuase the connection and manage it is very intuitive if you already know mysql,. Any idea ???.


      This is my code to test the database connection from nodeJS:

      var mysql = require('/home/root/node_modules/mysql');

      var connection = mysql.createConnection({

        host     : 'localhost',

        user     : 'root',

        password : 'admin',

        database : 'sensordatabase'



      connection.connect(function(err) {

        if (err) {

          console.error('error connecting: ' + err.stack);




        console.log('connected as id ' + connection.threadId);



      Error I get:


      root@edison:~/PFM_2015# node test.js

      error connecting: Error: connect ECONNREFUSED

          at errnoException (net.js:904:11)

          at Object.afterConnect [as oncomplete] (net.js:895:19)


          at Protocol._enqueue (/home/root/node_modules/mysql/lib/protocol/Protocol.js

          at Protocol.handshake (/home/root/node_modules/mysql/lib/protocol/Protocol.j

          at Connection.connect (/home/root/node_modules/mysql/lib/Connection.js:109:1

          at Object.<anonymous> (/home/root/PFM_2015/test.js:22:12)

          at Module._compile (module.js:456:26)

          at Object.Module._extensions..js (module.js:474:10)

          at Module.load (module.js:356:32)

          at Function.Module._load (module.js:312:12)

          at Function.Module.runMain (module.js:497:10)

          at startup (node.js:119:16)




      Thank you.