a year ago
I'm just new to render. I wanted to host my database which is MySQL.
but on deployment logs I see an error. I'm using the mysql docker image provided in the default config.
[Server] /usr/sbin/mysqld: ready for connections. Version: '8.3.0' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
May I know the reason or how to fix this?
10 Replies
a year ago
Sorry. I mean railway.
a year ago
That would have been funny if you did mean Render.
But you haven't provided any errors yet. What issues are you facing?
a year ago
Red doesn't always mean error, in this case, they are red because MySQL sent the logs to stderr.
Looking at the contents of the logs and not the color, I'm not seeing any errors, so please tell me what issues you are running into.
a year ago
So yeah, I have created another service which has a node + express + graphql. Then i'm trying to connect to the MySQL service.
but then i'm getting this from deployment log. I already filled up the env variables for the database.
Error: Error: connect ETIMEDOUT
at PoolConnection._handleTimeoutError (/app/node_modules/mysql2/lib/connection.js:205:17)
at listOnTimeout (node:internal/timers:569:17)
at process.processTimers (node:internal/timers:512:7) {
errorno: 'ETIMEDOUT',
code: 'ETIMEDOUT',
syscall: 'connect',
fatal: true
}
a year ago
Here.
const mysql = require('mysql2');
const pool = mysql.createPool({
host: process.env.DB_HOST,
user: process.env.DB_USER,
password: process.env.DB_PASSWORD || '',
database: process.env.DB_NAME,
connectionLimit: 10,
});
const keepConnectionAlive = async () => {
try {
const connection = await pool.promise().getConnection();
console.log('Connected to the database');
await connection.query('SELECT 1');
console.log('Connection live');
connection.release();
} catch (err) {
console.error('Error:', err);
}
};
const interval = 50000;
setInterval(keepConnectionAlive, interval);
module.exports = { pool };
a year ago
Thanks for the help. Already solved it!
a year ago
Happy you solved it, and for anyone else, they were missing the port
field in their pool object.
Status changed to Solved Railway • over 1 year ago