I'm creating a bot for discord that has a connection to mysql. So far, it was working normally but after changing the server where I host the mysql server (it was always remote), it started giving this error:
Error: Connection lost: The server closed the connection.
The code where I run the query and create the connection to the server is this:
const connection = mysql.createConnection({
host: config.host,
user: config.dbUser,
password: config.dbPassword,
database: config.database
});
connection.connect(function(err) {
if (err) {
console.error("[MYSQL] Error: " + err.stack);
return;
}
console.log("[MYSQL] Connected with ID " + connection.threadId + "!");
});
function query(sql) {
return new Promise(resolve => {
connection.query(sql, function(error, result, fields) {
if (error) return error;
const analise = JSON.stringify(result[0]);
const final = JSON.parse(analise);
resolve(final);
});
});
}
exports.connection = connection;
exports.query = query;
Can someone help me?