无法将mysql与nodejs连接

时间:2017-03-17 21:33:50

标签: mysql node.js

我是node.js的新手。当Iam尝试将mysql与node.js连接时,我得到了这个。真的在寻求帮助。

  

{错误:连接ECONNREFUSED 127.0.0.1:8889     at Object.exports._errnoException(util.js:1022:11)    在exports._exceptionWithHostPort(util.js:1045:20)

     

at TCPConnectWrap.afterConnect [as oncomplete](net.js:1087:14)

     

at Protocol._enqueue(/Applications/MAMP/htdocs/htbf/nodejsdb/mysql/node_modules/mysql/lib/protocol/Protocol.js:141:48)       在Protocol.handshake(/Applications/MAMP/htdocs/htbf/nodejsdb/mysql/node_modules/mysql/lib/protocol/Protocol.js:52:41)       在Connection.connect(/Applications/MAMP/htdocs/htbf/nodejsdb/mysql/node_modules/mysql/lib/Connection.js:130:18)       在Connection._implyConnect(/Applications/MAMP/htdocs/htbf/nodejsdb/mysql/node_modules/mysql/lib/Connection.js:461:10)       在Connection.query(/Applications/MAMP/htdocs/htbf/nodejsdb/mysql/node_modules/mysql/lib/Connection.js:206:8)       在对象。 (/Applications/MAMP/htdocs/htbf/nodejsdb/mysql/app1.js:11:12)       在Module._compile(module.js:570:32)       在Object.Module._extensions..js(module.js:579:10)       在Module.load(module.js:487:32)       在tryModuleLoad(module.js:446:12)     代码:' ECONNREFUSED',     错误:' ECONNREFUSED',     系统调用:' connect',     地址:' 127.0.0.1',     港口:8889,     致命的:真实的}

     

我的代码是       var mysql = require(' mysql');

var connection = mysql.createConnection({
host: 'localhost',
port: '8889',
user: 'root',
password: 'root',
socket: '/Applications/MAMP/tmp/mysql/mysql.sock',
database: 'login_db'
});
connection.query('SELECT * from test_table',function(err,rows,feilds){
if(!err){
    console.log(rows);
} else{
    console.log(err);
}
});
connection.end();

0 个答案:

没有答案