Home > other >  listen EADDRINUSE: address already in use :::3306 when attempting connection with MySQL server via N
listen EADDRINUSE: address already in use :::3306 when attempting connection with MySQL server via N

Time:06-09

I am experiencing problems with MySQL connection since making a few changes, and exhausted all suggestions, found here and the net as well as official troubleshooting docs, I come here in the hope of help.

The problem. When trying to connect to MySQL DB via Node.JS (VSC)

Error: listen EADDRINUSE: address already in use :::3306

Node works on all Ports as requested, apart from any port that MySQL uses. Also MySQL connection fails if either the port number is edited or a new instance created.

A little history of the problem: Worked perfectly with Node.JS app MySQL DB Workbench 8.0 (MWB). Could connect and webpage populated with data from DB with no issues until i hooked it up to AWS Elastic Beanstalk, which I have since delete but problem persists even though I'm back at the beginning.

CodePudding user response:

3306 is the port MySQL listens on. Your NodeJS app should not try to also listen on that port.

You should be specifying port 3306 here:

const db = mysql.createConnection({
host: "localhost",
user: "root",
password: "root12345",
});

Not here:

app.listen(PORT, () => {
 console.log(`listening to port: ${PORT}`);
});

Your app should probably be listing on port 80 or 443 or whatever is appropriate for whatever your NodeJS app is trying to do. It may not need to listen on any port at all.


Also, you are using local MySQL here, you aren't making a connection to RDS at all, you are making a connection to the MySQL software running on the same server as the NodeJS app.

  • Related