Guest User

Untitled

a guest
Aug 5th, 2018
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. mysql connection error :Error: Connection lost: The server closed the connection.
  2. { Error: Connection lost: The server closed the connection.
  3. at Protocol.end (/home/yeju/server/roomatching/node_modules/mysql/lib/protocol/Protocol.js:112:13)
  4. at Socket.<anonymous> (/home/yeju/server/roomatching/node_modules/mysql/lib/Connection.js:97:28)
  5. at Socket.<anonymous> (/home/yeju/server/roomatching/node_modules/mysql/lib/Connection.js:502:10)
  6. at emitNone (events.js:91:20)
  7. at Socket.emit (events.js:188:7)
  8. at endReadableNT (_stream_readable.js:975:12)
  9. at _combinedTickCallback (internal/process/next_tick.js:80:11)
  10. at process._tickCallback (internal/process/next_tick.js:104:9)
  11. --------------------
  12. at Protocol._enqueue (/home/yeju/server/roomatching/node_modules/mysql/lib/protocol/Protocol.js:144:48)
  13. at Protocol.handshake (/home/yeju/server/roomatching/node_modules/mysql/lib/protocol/Protocol.js:51:23)
  14. at Connection.connect (/home/yeju/server/roomatching/node_modules/mysql/lib/Connection.js:118:18)
  15. at Object.test_open (/home/yeju/server/roomatching/db/db_con.js:17:11)
  16. at Object.<anonymous> (/home/yeju/server/roomatching/database.js:3:11)
  17. at Module._compile (module.js:571:32)
  18. at Object.Module._extensions..js (module.js:580:10)
  19. at Module.load (module.js:488:32)
  20. at tryModuleLoad (module.js:447:12)
  21. at Function.Module._load (module.js:439:3) fatal: true, code: 'PROTOCOL_CONNECTION_LOST' }
  22.  
  23. function handleDisconnect() {
  24. connection = mysql.createConnection(db_config); // Recreate the connection, since
  25. // the old one cannot be reused.
  26.  
  27. connection.connect(function(err) { // The server is either down
  28. if(err) { // or restarting (takes a while sometimes).
  29. console.log('error when connecting to db:', err);
  30. setTimeout(handleDisconnect, 2000); // We introduce a delay before attempting to reconnect,
  31. } // to avoid a hot loop, and to allow our node script to
  32. }); // process asynchronous requests in the meantime.
  33. // If you're also serving http, display a 503 error.
  34. connection.on('error', function(err) {
  35. console.log('db error', err);
  36. if(err.code === 'PROTOCOL_CONNECTION_LOST') { // Connection to the MySQL server is usually
  37. handleDisconnect(); // lost due to either server restart, or a
  38. } else { // connnection idle timeout (the wait_timeout
  39. throw err; // server variable configures this)
  40. }
  41. });
  42. }
  43.  
  44. module.exports = (function () {
  45. return {
  46. local: { // localhost
  47. host: 'localhost',
  48. port: '4000',
  49. user: 'root',
  50. password: 'password',
  51. database: 'database'
  52. },
  53. real: { // real server db info
  54. host: '',
  55. port: '',
  56. user: '',
  57. password: '!',
  58. database: ''
  59. },
  60. dev: { // dev server db info
  61. host: '',
  62. port: '',
  63. user: '',
  64. password: '',
  65. database: ''
  66. }
  67. }
  68. })();
  69.  
  70. var mysql = require('mysql');
  71. var config = require('../db/db_info').local;
  72.  
  73. module.exports = function () {
  74. return {
  75. init: function () {
  76. return mysql.createConnection({
  77. host: config.host,
  78. port: config.port,
  79. user: config.user,
  80. password: config.password,
  81. database: config.database
  82. })
  83. },
  84.  
  85. test_open: function (con) {
  86. con.connect(function (err) {
  87. console.log('hi');
  88. if (err) {
  89. console.error('mysql connection error :' + err);
  90. } else {
  91. console.info('mysql is connected successfully.');
  92. }
  93. })
  94. }
  95. }
  96. };
  97.  
  98. var mysql_dbc = require('./db/db_con')();
  99. var connection = mysql_dbc.init();
  100. mysql_dbc.test_open(connection);
  101.  
  102. var express = require('express');
  103. var router = express.Router();
  104. var db = require('../database');
Add Comment
Please, Sign In to add comment