When to close MySQL connection using node-mysql?

connection.end() does it job regardless to fatal error. If a fatal error occurs before the COM_QUIT packet can be sent, an err argument will be provided to the callback, but the connection will be terminated regardless of that.

Also check destroy() method. This will cause an immediate termination of the underlying socket.

You can add error handler.

https://github.com/felixge/node-mysql/blob/master/Readme.md#error-handling

// I am Chuck Norris:
connection.on('error', function() {});

Once terminated, an existing connection object cannot be re-connected by design.

Check here. It’s showing connecting back after disconnect.

https://github.com/felixge/node-mysql/blob/master/Readme.md#server-disconnects

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)