79772526

Date: 2025-09-23 11:30:20
Score: 2.5
Natty:
Report link

It looks like the error happens because you’re using a single MySQL connection (mysql.createConnection) instead of a pool. A single connection can drop if the server restarts or if it times out, which is why you get PROTOCOL_CONNECTION_LOST.

A better approach is to use a connection pool. That way MySQL automatically reuses or refreshes connections:

const mysql = require('mysql2');

const pool = mysql.createPool({
  host: 'localhost',
  user: 'root',
  password: '',
  database: 'charity_tracker',
  waitForConnections: true,
  connectionLimit: 10,
  queueLimit: 0
});

module.exports = pool.promise();

Using a pool usually fixes the “connection lost” problem.

If you still get the same issue, check the MySQL error logs. Sometimes tables get corrupted after crashes, and that can also cause random disconnects. You can run:

CHECK TABLE users;
CHECK TABLE donations;
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Me too answer (2.5): get the same issue
  • Low reputation (1):
Posted by: Arun Pratap