Closed ghost closed 2 years ago
Hi! There are two methods:
I hope this helps!
I see, so if I just did
con.connect(function(err) {
if (err) {
console.error('error connecting, trying again: ');
await new Promise(resolve => setTimeout(resolve, 30000));
con.connect();
}
console.log('connected as id ' + con.threadId);
});
, would it hopefully just work without a problem? I'm kind of new to Node, sorry if this is a bad solution.
Never mind, just tried it out and this type of wait only works in asynchronous functions apparently.
fulpbot | Error: connect ECONNREFUSED 127.0.0.1:3306
fulpbot | at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
I made it keep retrying, but this happens every single time. I'm guessing this is a docker issue, because my Docker's apache connects just fine to it.
var con = mysql.createConnection({
host: "localhost",
user: process.env.MYSQL_USER,
password: process.env.MYSQL_PASSWORD,
database: process.env.MYSQL_DATABASE
});
FROM node:14.15.2
WORKDIR /usr/src/fulpbot
COPY package*.json ./
RUN npm i
COPY . .
CMD [ "node", "./src/bot.js" ]
discordbot:
build:
context: ./fulpbot
depends_on:
- sql
networks:
- fulp_vnet
environment:
- MYSQL_USER=root
- MYSQL_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_DATABASE=fulptube
- MYSQL_HOST=sql
- DISCORD_TOKEN=discordtoken
container_name: fulpbot
Ask me if you need more info, i'm kind of confused why it's refusing the connection.
Also, yes, Apache does use the same environment variables.
php:
build:
context: ./phpwsql
depends_on:
- sql
networks:
- fulp_vnet
environment:
- MYSQL_USER=root
- MYSQL_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_DATABASE=fulptube
- MYSQL_HOST=sql
volumes:
- ./www/:/var/www/html
- ./www/dynamic/:/dynamic
ports:
- "80:80"
container_name: fulpphp```
Real.
Real.
Hi, unfortunately connecting to your MySQL server is outside the scope of this module; if Node.js says the connection is refused, there is something wrong in the environment in some way, or perhaps Node.js itself cannot connect.
Hello, I'm making a website and I use Docker to combine everything. I've made a discord bot to manage content for the site. The bot worked on my local machine (not using Docker), and apparently my discord bot starts faster than MySQL, so when the bot tries to connect, it refuses the connection. My friend made a queuer for my site to process videos, and it has a section to keep retrying to connect since he knows that it won't connect on the first try because of Docker. Is there a way to keep trying to reconnect using MySQLjs? Thank you.