amine
amine

Reputation: 31

connect to mysql database hosted on ec2 aws from localhost using nodejs

i'm trying to connect to mysql database hosted on ec2 instence on aws, but i'm getting the error: errno: -111, code: 'ECONNREFUSED', syscall: 'connect', address: '15.188.51.165', port: 3306, fatal: true

my code :

  const con = mysql.createConnection({
        host: "********.com",
        user: "root",
        password: "******",
        database : '***[![enter image description here][1]][1]',
        port:'3306',
        multipleStatements: true
      });

Upvotes: 0

Views: 957

Answers (1)

Shivam Anand
Shivam Anand

Reputation: 1611

To be able to connect to mysql server in an ec2 from outside you need to verify these points 0. Check if your mysql server is accessible from your ec2

  1. Check if your ec2 OS firewall has connectivity from where you are accessing. Check if firewall allows connection via 3306. For ubuntu you can refer this
  2. Check if your security group allows connection from where you are accessing. Please open port 3306 from security group.
  3. Verify if your mysql server is in a public or private subnet. If it is in a private subnet, your network configuration for sql client should be such that you are able to access it.

These rules apply for all/most OS. If these points align you should be able to access your server.

Upvotes: 0

Related Questions