相关疑难解决方法(0)

Node.js MySQL需要持久连接

我的Node Web应用程序需要持久的MySQL连接.问题是这种情况每天发生几次:

Error: Connection lost: The server closed the connection.
at Protocol.end (/var/www/n/node_modules/mysql/lib/protocol/Protocol.js:73:13)
at Socket.onend (stream.js:79:10)
at Socket.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:895:16
at process._tickCallback (node.js:415:13)
error: Forever detected script exited with code: 8
error: Forever restarting script for 2 time
info: socket.io started
Run Code Online (Sandbox Code Playgroud)

这是我的连接代码:

// Yes I know multipleStatements can be dangerous in the wrong hands.
var sql = mysql.createConnection({
    host: 'localhost',
    user: 'my_username',
    password: 'my_password',
    database: 'my_database',
    multipleStatements: true
});

sql.connect();

function handleDisconnect(connection) {
    connection.on('error', function(err) {
        if (!err.fatal) { …
Run Code Online (Sandbox Code Playgroud)

mysql node.js node-mysql

36
推荐指数
3
解决办法
3万
查看次数

标签 统计

mysql ×1

node-mysql ×1

node.js ×1