title: ER_ACCESS_DENIED_ERROR: Access denied for user ''@'localhost' (using password: NO)
body: <p>I have this problem, I already researched and I could not solve it, I imagine it has something to do with database permissions, but I can not fix it:</p>
  
  <pre><code>if (error) throw error;
         ^
  
  Error: ER_ACCESS_DENIED_ERROR: Access denied for user ''@'localhost' (using password: NO)
  at Handshake.Sequence._packetToError (/home/carlos/www/express-cc/node_modules/mysql/lib/protocol/sequences/Sequence.js:52:14)
  at Handshake.ErrorPacket (/home/carlos/www/express-cc/node_modules/mysql/lib/protocol/sequences/Handshake.js:103:18)
  at Protocol._parsePacket (/home/carlos/www/express-cc/node_modules/mysql/lib/protocol/Protocol.js:279:23)
  at Parser.write (/home/carlos/www/express-cc/node_modules/mysql/lib/protocol/Parser.js:76:12)
  at Protocol.write (/home/carlos/www/express-cc/node_modules/mysql/lib/protocol/Protocol.js:39:16)
  at Socket.&lt;anonymous&gt; (/home/carlos/www/express-cc/node_modules/mysql/lib/Connection.js:103:28)
  at emitOne (events.js:115:13)
  at Socket.emit (events.js:210:7)
  at addChunk (_stream_readable.js:266:12)
  at readableAddChunk (_stream_readable.js:253:11)
  --------------------
  at Protocol._enqueue (/home/carlos/www/express-cc/node_modules/mysql/lib/protocol/Protocol.js:145:48)
  at Protocol.handshake (/home/carlos/www/express-cc/node_modules/mysql/lib/protocol/Protocol.js:52:23)
  at Connection.connect (/home/carlos/www/express-
  cc/node_modules/mysql/lib/Connection.js:130:18)
  at Object.&lt;anonymous&gt; (/home/carlos/www/express-cc/db.js:10:12)
  at Module._compile (module.js:573:30)
  at Object.Module._extensions..js (module.js:584:10)
  at Module.load (module.js:507:32)
  at tryModuleLoad (module.js:470:12)
  at Function.Module._load (module.js:462:3)
  at Module.require (module.js:517:17)
  </code></pre>
  
  <p><strong>---- EDIT -----</strong></p>
  
  <p>my env.default file:</p>
  
  <pre><code>NODE_ENV=DEVELOPMENT
  
  DB_HOST=localhost
  DB_USER=user
  DB_PASSWORD=userpass
  DB_NAME=teste
  </code></pre>
  
  <p>so this my db.js file:</p>
  
  <pre><code> var mysql = require('mysql')
    var connection = mysql.createConnection({
    host: process.env.DB_HOST,
    user: process.env.DB_USER,
    password: process.env.DB_PASSWORD,
    database : process.env.DB_NAME,
    sockertPath: '/var/run/mysqld/mysqld.sock'
  })
  
   connection.connect()
  
   connection.query('SELECT 1 + 1 AS solution',
   function (error, results, fields) {
  if (error) throw error;
  console.log('The solution is: ', results[0].
    solution)
  });
  
   module.exports = connection;
  </code></pre>