A
A
Asikov Artur2018-03-09 18:26:35
MySQL
Asikov Artur, 2018-03-09 18:26:35

Why is the connection to the database automatically disconnected?

const db = mysql.createConnection({
    host:  'localhost',
    user: 'root',
    password: '',
    database: 'mydb'
});

db.connect((err) => {
    if(err){
        throw err;
    }
    console.log('MySql connected');
    });

Everything works fine, in the console I see
MySql connected
Approximately 40-50 seconds later the server breaks the connection with the words. Breaks even in case of complete inactivity of the client.
events.js:183
      throw er; // Unhandled 'error' event
      ^
Error: Connection lost: The server closed the connection.
    at Protocol.end (C:\Users\asik\Desktop\copy\node_modules\mysql\lib\protocol\Protocol.js:113:13)
    at Socket.<anonymous> (C:\Users\asik\Desktop\copy\node_modules\mysql\lib\Connection.js:109:28)
    at emitNone (events.js:111:20)
    at Socket.emit (events.js:208:7)
    at endReadableNT (_stream_readable.js:1056:12)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis, 2018-03-09
@Artur937

well, in my opinion, in the MySQL settings there is a connection timeout connect_timeout
or make a reconnect mechanism

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question