私はこの問題を抱えていますが、私はすでに調査して解決できませんでした。それを修正ません:ER_ACCESS_DENIED_ERROR:ユーザー '' @ 'localhost'のアクセスが拒否されました(パスワードはNOを使用)
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.<anonymous> (/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.<anonymous> (/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)
---- EDIT -----
私env.defaultファイル:
NODE_ENV=DEVELOPMENT
DB_HOST=localhost
DB_USER=user
DB_PASSWORD=userpass
DB_NAME=teste
ので、この私のdb.jsファイル:
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;
先生に感謝、それは働いている! – Techtique