Node.js - Error connection lost the server closed the connection
Error: Connection lost: The server closed the connection.
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();
출처 :
http://stackoverflow.com/questions/20210522/nodejs-mysql-error-connection-lost-the-server-closed-the-connection
http://hangaebal.blogspot.kr/2014/06/nodejs-error-connection-lost-server.html
'Blogger 이사' 카테고리의 다른 글
[Spring] Map, Properties 값 설정 (0) | 2016.01.14 |
---|---|
[Java] Difference between Set, List and Map in Java (0) | 2016.01.14 |
[Spring] Spring web 프로젝트 준비 (Eclipse, Gradle) (0) | 2016.01.14 |
[Java] java.math.BigDecimal 활용 Discount, Tax (0) | 2016.01.14 |
[JavaScript] JavaScript get Object Length (0) | 2016.01.14 |