title: nodejs mysql Error: Connection lost The server closed the connection
body: <p>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:</p>
  
  <pre><code>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)
  </code></pre>
  
  <p>There is the <a href="https://github.com/felixge/node-mysql#server-disconnects" rel="noreferrer">solution</a>. However, after I try by this way, the problem also appear. now I do not know how to do. Does anyone meet this problem?</p>
  
  <p>Here is the way I wrote follow the solution:</p>
  
  <pre><code>    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();
  </code></pre>