当我与Sequelize
建立连接时:
var Sequelize = require('sequelize'),
sequelize = new Sequelize('development', 'root', 'root',
{ host: '127.0.0.1',
dialect: "mysql",
port: 3001
});
我收到以下错误:
无法连接到数据库:{SequelizeConnectionError: 连接丢失:服务器关闭了连接。在 Handshake._callback (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:94:20) 在Handshake.Sequence.end (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/mysql/lib/protocol/sequences/Sequence.js:85:24) 在 /home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/mysql/lib/protocol/Protocol.js:399:18 在Array.forEach(native)at /home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/mysql/lib/protocol/Protocol.js:398:13 在_combinedTickCallback(内部/进程/ next_tick.js:67:7)at process._tickCallback(internal / process / next_tick.js:98:9)名称: ' SequelizeConnectionError',消息:'连接丢失:服务器 关闭连接。',父:{错误:连接丢失: 服务器关闭了连接。在Protocol.end (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/mysql/lib/protocol/Protocol.js:109:13) 在Socket。 (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/mysql/lib/Connection.js:115:28) 在Socket.emit的emitNone(events.js:91:20)(events.js:185:7) at endReadableNT(_stream_readable.js:973:12)at _combinedTickCallback(internal / process / next_tick.js:74:11)at process._tickCallback(internal / process / next_tick.js:98:9)
--------------------在Protocol._enqueue(/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/mysql/lib/protocol/Protocol.js:141: 48) 在Protocol.handshake (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/mysql/lib/protocol/Protocol.js:52:41) 在Connection.connect (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/mysql/lib/Connection.js:136:18) 在 /home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:74:16 在Promise._execute (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/bluebird/js/release/debuggability.js:284:9) 在Promise._resolveFromExecutor (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/bluebird/js/release/promise.js:480:18) 在新的承诺 (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/bluebird/js/release/promise.js:77:14) 在ConnectionManager.connect (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:55:10) 在 。 (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:247:43)在tryCatcher上 (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/bluebird/js/release/util.js:16:23) 在Promise._settlePromiseFromHandler (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/bluebird/js/release/promise.js:509:31) 在Promise._settlePromise (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/bluebird/js/release/promise.js:566:18) 在Promise._settlePromise0 (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/bluebird/js/release/promise.js:611:10) 在Promise._settlePromises (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/bluebird/js/release/promise.js:690:18) 在Async._drainQueue (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/bluebird/js/release/async.js:138:16) 在Async._drainQueues (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/bluebird/js/release/async.js:148:10) 致命:真实,代码:' PROTOCOL_CONNECTION_LOST' }, 原版的: { 错误:连接丢失:服务器关闭了连接。在 Protocol.end (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/mysql/lib/protocol/Protocol.js:109:13) 在Socket。 (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/mysql/lib/Connection.js:115:28) 在Socket.emit的emitNone(events.js:91:20)(events.js:185:7) at endReadableNT(_stream_readable.js:973:12)at _combinedTickCallback(internal / process / next_tick.js:74:11)at process._tickCallback(internal / process / next_tick.js:98:9)
--------------------在Protocol._enqueue(/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/mysql/lib/protocol/Protocol.js:141: 48) 在Protocol.handshake (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/mysql/lib/protocol/Protocol.js:52:41) 在Connection.connect (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/mysql/lib/Connection.js:136:18) 在 /home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:74:16 在Promise._execute (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/bluebird/js/release/debuggability.js:284:9) 在Promise._resolveFromExecutor (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/bluebird/js/release/promise.js:480:18) 在新的承诺 (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/bluebird/js/release/promise.js:77:14) 在ConnectionManager.connect (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:55:10) 在 。 (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:247:43)在tryCatcher上 (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/bluebird/js/release/util.js:16:23) 在Promise._settlePromiseFromHandler (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/bluebird/js/release/promise.js:509:31) 在Promise._settlePromise (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/bluebird/js/release/promise.js:566:18) 在Promise._settlePromise0 (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/bluebird/js/release/promise.js:611:10) 在Promise._settlePromises (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/bluebird/js/release/promise.js:690:18) 在Async._drainQueue (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/bluebird/js/release/async.js:138:16) 在Async._drainQueues (/home/cbl61/WebstormProjects/register_mongo/sequelize/node_modules/bluebird/js/release/async.js:148:10) 致命:真实,代码:' PROTOCOL_CONNECTION_LOST' }}
答案 0 :(得分:0)
确保在建立连接时需要mysql
var mysql = require('mysql');
var Sequelize = require('sequelize');
var sequelize = new Sequelize('development', 'root', 'root', {
host: 'localhost', //or 127.0.0.1
dialect: 'mysql',
port: 3001 //optional
});
sequelize.sync();
确保数据库的开发'在场!