<tfoot id='vZgjd'></tfoot>
    <i id='vZgjd'><tr id='vZgjd'><dt id='vZgjd'><q id='vZgjd'><span id='vZgjd'><b id='vZgjd'><form id='vZgjd'><ins id='vZgjd'></ins><ul id='vZgjd'></ul><sub id='vZgjd'></sub></form><legend id='vZgjd'></legend><bdo id='vZgjd'><pre id='vZgjd'><center id='vZgjd'></center></pre></bdo></b><th id='vZgjd'></th></span></q></dt></tr></i><div id='vZgjd'><tfoot id='vZgjd'></tfoot><dl id='vZgjd'><fieldset id='vZgjd'></fieldset></dl></div>
  • <legend id='vZgjd'><style id='vZgjd'><dir id='vZgjd'><q id='vZgjd'></q></dir></style></legend>

      • <bdo id='vZgjd'></bdo><ul id='vZgjd'></ul>
    1. <small id='vZgjd'></small><noframes id='vZgjd'>

        nodejs mysql 错误:连接丢失 服务器关闭了连接

        时间:2023-08-18
        <tfoot id='xf4ja'></tfoot>

      1. <legend id='xf4ja'><style id='xf4ja'><dir id='xf4ja'><q id='xf4ja'></q></dir></style></legend>

          <small id='xf4ja'></small><noframes id='xf4ja'>

            <bdo id='xf4ja'></bdo><ul id='xf4ja'></ul>

                  <tbody id='xf4ja'></tbody>
                1. <i id='xf4ja'><tr id='xf4ja'><dt id='xf4ja'><q id='xf4ja'><span id='xf4ja'><b id='xf4ja'><form id='xf4ja'><ins id='xf4ja'></ins><ul id='xf4ja'></ul><sub id='xf4ja'></sub></form><legend id='xf4ja'></legend><bdo id='xf4ja'><pre id='xf4ja'><center id='xf4ja'></center></pre></bdo></b><th id='xf4ja'></th></span></q></dt></tr></i><div id='xf4ja'><tfoot id='xf4ja'></tfoot><dl id='xf4ja'><fieldset id='xf4ja'></fieldset></dl></div>
                2. 本文介绍了nodejs mysql 错误:连接丢失 服务器关闭了连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  当我使用node mysql时,在12:00到2:00之间出现一个错误,TCP连接被服务器关闭.这是完整的消息:

                  when I use node mysql, an error is appear between 12:00 to 2:00 that the TCP connection is shutdown by the server. This is the full message:

                  Error: Connection lost: The server closed the connection.
                  at Protocol.end (/opt/node-v0.10.20-linux-x64/IM/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:920:16
                  at process._tickCallback (node.js:415:13)
                  

                  有解决方案.但是,我按照这种方式尝试后,问题也出现了.现在我不知道该怎么办.有人遇到过这个问题吗?

                  There is the solution. However, after I try by this way, the problem also appear. now I do not know how to do. Does anyone meet this problem?

                  这是我按照解决方案编写的方式:

                  Here is the way I wrote follow the solution:

                      var handleKFDisconnect = function() {
                      kfdb.on('error', function(err) {
                          if (!err.fatal) {
                              return;
                          }
                          if (err.code !== 'PROTOCOL_CONNECTION_LOST') {
                              console.log("PROTOCOL_CONNECTION_LOST");
                              throw err;
                          }
                          log.error("The database is error:" + err.stack);
                  
                          kfdb = mysql.createConnection(kf_config);
                  
                          console.log("kfid");
                  
                          console.log(kfdb);
                          handleKFDisconnect();
                      });
                     };
                     handleKFDisconnect();
                  

                  推荐答案

                  尝试使用这段代码处理服务器断开连接:

                  Try to use this code to handle server disconnect:

                  var db_config = {
                    host: 'localhost',
                      user: 'root',
                      password: '',
                      database: 'example'
                  };
                  
                  var connection;
                  
                  function handleDisconnect() {
                    connection = mysql.createConnection(db_config); // Recreate the connection, since
                                                                    // the old one cannot be reused.
                  
                    connection.connect(function(err) {              // The server is either down
                      if(err) {                                     // or restarting (takes a while sometimes).
                        console.log('error when connecting to db:', err);
                        setTimeout(handleDisconnect, 2000); // We introduce a delay before attempting to reconnect,
                      }                                     // to avoid a hot loop, and to allow our node script to
                    });                                     // process asynchronous requests in the meantime.
                                                            // If you're also serving http, display a 503 error.
                    connection.on('error', function(err) {
                      console.log('db error', err);
                      if(err.code === 'PROTOCOL_CONNECTION_LOST') { // Connection to the MySQL server is usually
                        handleDisconnect();                         // lost due to either server restart, or a
                      } else {                                      // connnection idle timeout (the wait_timeout
                        throw err;                                  // server variable configures this)
                      }
                    });
                  }
                  
                  handleDisconnect();
                  

                  在你的代码中,我遗漏了 connection = mysql.createConnection(db_config);

                  In your code i am missing the parts after connection = mysql.createConnection(db_config);

                  这篇关于nodejs mysql 错误:连接丢失 服务器关闭了连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:MySQL - 在一个查询中更新具有不同值的多行 下一篇:JavaScript 可以连接 MySQL 吗?

                  相关文章

                  最新文章

                3. <tfoot id='W7kss'></tfoot>

                    <i id='W7kss'><tr id='W7kss'><dt id='W7kss'><q id='W7kss'><span id='W7kss'><b id='W7kss'><form id='W7kss'><ins id='W7kss'></ins><ul id='W7kss'></ul><sub id='W7kss'></sub></form><legend id='W7kss'></legend><bdo id='W7kss'><pre id='W7kss'><center id='W7kss'></center></pre></bdo></b><th id='W7kss'></th></span></q></dt></tr></i><div id='W7kss'><tfoot id='W7kss'></tfoot><dl id='W7kss'><fieldset id='W7kss'></fieldset></dl></div>
                    1. <small id='W7kss'></small><noframes id='W7kss'>

                        <bdo id='W7kss'></bdo><ul id='W7kss'></ul>
                      <legend id='W7kss'><style id='W7kss'><dir id='W7kss'><q id='W7kss'></q></dir></style></legend>