node-mysql2
node-mysql2 copied to clipboard
Connection Timeout on ubuntu 22.04 (works fine on windows)
Hello,
I'm encountering a connection timeout issue on Ubuntu, the exact same code works flawlessly on Windows
I'm new to ExpressJS and am trying to create an API using mysql2
I have checked all firewalls, ports, etc., but I'm still facing this problem. i mean It's working on Windows for some reason but not on Ubuntu.
Node.js Version: v20.15.0 on both systems mysql2: v3.10.2 Database: MariaDB (connecting to the same database on both Windows and Ubuntu)
Error:
Listening on port: 4300
Error connecting to the database: Error: connect ETIMEDOUT
at PoolConnection._handleTimeoutError (/root/api/node_modules/mysql2/lib/connection.js:205:17)
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7) {
errorno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect',
fatal: true
}
Connection code
(async () => {
try {
const connection = await pool.getConnection();
console.log("Connected to the database");
connection.release();
} catch (err) {
console.error("Error connecting to the database:", err);
process.exit(1);
}
})();
database file
import dotenv from 'dotenv';
import mysql from 'mysql2/promise';
dotenv.config();
const pool = mysql.createPool({
host: process.env.HOST,
user: process.env.USER,
password: process.env.PASSWORD,
database: process.env.DATABASE
});
export default pool;
The code is straightforward, I don't understand why it will have problems on Ubuntu.