title: Establishing a connection between Node.js and MySQL
body: <p>I'm a complete newbie to Node.js, but I do have some experience with mysql and some other languages.</p>
  
  <p>I am trying to establish a database connection between Node.js and MySQL, however, my terminal keeps on giving me errors. It failed, so I tried to debug it by using "error.stack" as stated from the documentation, that failed also so I'm totally lost now. Can someone please help me to figure out the bug.</p>
  
  <p>Also, can anyone also tell me how to tell Node.js to print out the reason of why it failed to connect to the database like the function "mysql_error()" from PHP.</p>
  
  <p>My original Node.js code:</p>
  
  <pre><code>var MySQL = require('mysql');
  var DatabaseConnection = MySQL.createConnection({
   host: '10.0.0.25',
   user: 'Admin',
   password: 'Password'
  });
  DatabaseConnection.connect(function(error) {
   if(!error) {
    console.log("Database is connected");
    return;
   } else {
    console.log("Database is not connected: ");
    console.log(error.stack);
   }
  });
  </code></pre>
  
  <p>My result:</p>
  
  <pre><code>Database is not connected: 
  Error: connect ECONNREFUSED 10.0.0.25:3306
      at Object._errnoException (util.js:1022:11)
      at _exceptionWithHostPort (util.js:1044:20)
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1182:14)
      --------------------
      at Protocol._enqueue (/Users/marc/Documents/JSON_MySQL_Database_Test/node_modules/mysql/lib/protocol/Protocol.js:145:48)
      at Protocol.handshake (/Users/marc/Documents/JSON_MySQL_Database_Test/node_modules/mysql/lib/protocol/Protocol.js:52:23)
      at Connection.connect (/Users/marc/Documents/JSON_MySQL_Database_Test/node_modules/mysql/lib/Connection.js:130:18)
      at Object.&lt;anonymous&gt; (/Users/marc/Documents/JSON_MySQL_Database_Test/Database_Test.js:8:20)
      at Module._compile (module.js:643:30)
      at Object.Module._extensions..js (module.js:654:10)
      at Module.load (module.js:556:32)
      at tryModuleLoad (module.js:499:12)
      at Function.Module._load (module.js:491:3)
      at Function.Module.runMain (module.js:684:10)
  </code></pre>