title: How to connect to MySQL using node.js (with node-mysql driver)?
body: <p>I have the following code, which I am trying to run. I have given comments accordingly to mention what all I have tried.</p>
  
  <pre><code>// File saved as app.js
  var mysql = require('mysql');
  var connection = mysql.createConnection({
      host:'localhost',    //even tried with 127.0.0.1
      port:3306,           //confirmed port by looking into /etc/mysql/my.cnf has [client] port = 3306
      user:'root',         //credentials are verified since Php My Admin logs in with same
      password:'password' //credentials are verified since Php My Admin logs in with same
      //Even tried to connect using _socket: '/var/run/mysqld/mysqld.sock'
  });
  
  connection.connect(function(err) {
    // connected! (unless `err` is set)
    if(err)
      console.log(err); return;
  });
  </code></pre>
  
  <p>Since the default port is not changed, the phpMyAdmin is working fine for me. But I am not able to connect using <a href="https://github.com/felixge/node-mysql" rel="nofollow">node-mysql driver</a> from <a href="http://nodejs.org/" rel="nofollow">Node.js</a>.</p>
  
  <p>The following is the error message I am getting:</p>
  
  <pre><code>amolkulkarni@ubuntu:~/Project/Node_MySQL$ node app.js
  { [Error: connect ECONNREFUSED]
    code: 'ECONNREFUSED',
    errno: 'ECONNREFUSED',
    syscall: 'connect',
    fatal: true }
  </code></pre>
  
  <p>Could anyone please help on this?</p>
  
  <p><hr/>
  <strong>Update:</strong> Based on comments</p>
  
  <pre><code> amolkulkarni@ubuntu:~/ ps ax | grep mysqld
   5905 ?        S      0:00 sudo /usr/sbin/mysqld --skip-grant-tables --skip-networking
   5906 ?        Sl     0:12 /usr/sbin/mysqld --skip-grant-tables --skip-networking
   28964 ?        Ssl    0:00 /usr/sbin/mysqld
   29098 pts/3    S+     0:00 grep --color=auto mysqld
  </code></pre>
  
  <p>I am able to connect to mysql using <code>mysql -hlocalhost -uroot -ppassword</code> but if I replace with ip e.g. <code>mysql -h192.168.1.10 -uroot -ppassword</code> It gives error as follows:</p>
  
  <blockquote>
    <p>ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.3.78' (111)</p>
  </blockquote>