Consider what would happen if your script relied on LAST_INSERT_ID() and mysql connection have been reset without you being aware about it? node.js - Node server connection to MySQL gets lost - Stack Overflow All of these events are considered fatal errors, and will have theerr.code = 'PROTOCOL_CONNECTION_LOST'. It will fail, as expected, in all others scenarios. Try to usethis codeto handle server disconnect: In your code i am missing the parts afterconnection = mysql.createConnection(db_config); Hello @kartik, Either way, Patrik is not wrong I thoroughly do not recommend this solution for anything other than a dirty hack when running a single process on a local machine. Thats when I realized that this is fantastic only while all systems are running. When you request a connection from a pool, you are either given a connection that is currently not being used or a new connection. The path to a unix domain socket to connect to. (Default: 10 seconds), Stringify objects instead of converting to values. This is the full message: There is the solution. Whenever the app needs to perform queries with the database, I would include the database.js file and have the pool available like so: Readers have frequently asked whether connections are automatically released back into the pool after theyve been used. Step 1: Install the mysql package for Node.js using the following command: npm install mysql Step 2: Create a connection to your MySQL database using the createConnection method and set the connectTimeout option to a higher value (in milliseconds) than the default value of 10 seconds. The charset for the connection. Refactoring MySQL to Node.js 8's Async/Await. Error: Cannot enqueue Query after fatal error. Expressjs. Mysql The ssl option in the connection options takes a string or an object. Note that in your code you had an incorrect message: Just a tip: I'm testing reconnecting by restarting mysql service to ensure everything works well. For testing, the proxy code is as per the vanilla example with the exception that we set the sequencId to 0 in the authCallback and to 1 on query. See the Error Handling section for more information. Why Is PNG file with Drop Shadow in Flutter Web App Grainy? I have deployed Pomelo server on AWS EC2 (Ubuntu) instance. Running this node example: #1268 error error: { Error: Connection lost: The server closed the connection. The problem is mysql driver lost the connection and can't resume the connection if there is no reboot. This attack can bypass a firewall and can affect a fully patched system. Nowadays, I cannot think of any valid use case. A connection pool is a cache of database connections maintained so that the connections can be reused when future requests to the database are required. 2 Answers Sorted by: 4 You already seem to know what is happening; the MySQL server is closing the connection. You can terminate a connection by calling the end() method : This will make sure all previously enqueued queries are still before sending a COM_QUIT packet to the MySQL server. Not the answer you're looking for? All of these events are considered fatal errors. To learn more, see our tips on writing great answers. Connection socket management is expensive, therefore strive to limit how long you keep the connections open.