未处理的拒绝SequelizeConnectionRefusedError:连接ECONNREFUSED 127.0.0.1:3306

时间:2019-09-11 10:08:25

标签: javascript mysql node.js database express

         date  amount  category
0  2018-09-01   -58.0    dinner
1  2018-09-02   -60.0   grocery
2  2018-09-02  -115.0  clothing

我在使用数据库(MySQL)时遇到问题。

我想使用express链接我的Web服务器和数据库 但是有一条错误消息

Unhandled rejection SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306
    at Promise.tap.then.catch.err (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:123:19)
From previous event:
    at ConnectionManager.connect (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:120:13)
    at sequelize.runHooks.then (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:311:50)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)
From previous event:
    at ConnectionManager._connect (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:311:8)
    at ConnectionManager.getConnection (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:247:46)
    at Promise.try (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/sequelize.js:638:36)
From previous event:
    at Promise.resolve.retry (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/sequelize.js:629:53)
    at /Users/wooseungjin/codlab-nodejs/node_modules/retry-as-promised/index.js:70:21
    at new Promise (<anonymous>)
    at retryAsPromised (/Users/wooseungjin/codlab-nodejs/node_modules/retry-as-promised/index.js:60:10)
    at Promise.try (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/sequelize.js:629:30)
From previous event:
    at Sequelize.query (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/sequelize.js:578:23)
    at QueryInterface.dropTable (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/query-interface.js:254:27)
    at Function.drop (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/model.js:1388:32)
    at Promise.each.model (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/sequelize.js:873:48)
From previous event:
    at Sequelize.drop (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/sequelize.js:873:20)
    at Promise.try.then (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/sequelize.js:798:21)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)
From previous event:
    at Sequelize.sync (/Users/wooseungjin/codlab-nodejs/node_modules/sequelize/lib/sequelize.js:796:8)
    at Server.app.listen (/Users/wooseungjin/codlab-nodejs/app.js:16:33)
    at Object.onceWrapper (events.js:286:20)
    at Server.emit (events.js:198:13)
    at emitListeningNT (net.js:1313:10)
    at process._tickCallback (internal/process/next_tick.js:63:19)
    at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)

为什么会出现错误?

Unhandled rejection SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306

2 个答案:

答案 0 :(得分:0)

您的SQL服务器未运行或节点应用程序无权访问错误的唯一原因

答案 1 :(得分:0)

检查mySql服务器状态。

sudo service mysql status

ps aux | grep mysql

如果您的服务器处于活动状态,则

//Setting up the config

var sequelize = new Sequelize('your-database-name', 'db-username', 'db-password', {
    host: 'localhost',
    dialect: 'mysql' // pick one of 'mysql','sqlite','postgres','mssql',
    port: 3306,
});


//Checking connection status


sequelize.authenticate().complete(function (err) {
 if (err) {
    console.log('There is connection in ERROR');
 } else {
    console.log('Connection has been established successfully');
 }
});