Question

HOW can i solve the Error: connect ETIMEDOUT when try to connect node with DO Mysql database

Posted August 21, 2020 1.6k views
Databases
const MYSQL_CONF = {
    host: 'db-mysql-v1-29254-do-user-7904424-0.a.db.ondigitalocean.com',
    username: 'doadmin',
    password: 'xxxxxxxx',
    database: 'defaultdb',
    // port: 25060,
    dialect: 'mysql',
    dialectOptions: {
        ssl: {
            ssl: true,
            cert: fs.readFileSync(path.resolve(__dirname, 'ca-certificate.crt')).toString('utf8')
        }
    }
}

const con = mysql.createConnection(MYSQL_CONF)
con.connect((err, result) => {
    if (err) {
        throw new Error(err)
        return
    }
});

The configuration is coded above, and i am not sure if this is the correct one…The error always states the Error: connect ETIMEDOUT..

the funny thing is that i can connect the cluster with mysql client terminal and workbench on my local machine, but it doesn’t work with node.js....

Could someone help me out, many thanks?

edited by bobbyiliev

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
2 answers

Hi there @zhangboyu,

I can see that the custom port is commented out, you need to have that port specifically defined in your connection string.

Another thing that I would recommend trying to create a new user with MySQL native password and try using it instead of the default user. You can do that via your DigitalOcean control panel.

Also if your Node.js app is running on a Droplet, I would recommend checking if port 25060 is open for outgoing TCP connections, to test that you can use the following telnet command:

  • telnet your_db_host.db.ondigitalocean.com 25060

Let me know how it goes!
Regards,
Bobby

  • Hi Bobby

    Many thanks for the help. But it seems still not working.
    I have done all the instructed things..but…
    The coding’s here:

    const fs = require('fs')
    const path = require('path')
    
    
    const MYSQL_CONF = {
        username: 'JerryZ',
        password: 'xxxxxxxxxxxx',
        database: 'defaultdb',
        host: 'db-mysql-v1-29254-do-user-7904424-0.a.db.ondigitalocean.com',
        port: 25060,
        dialect: 'mysql',
        dialectOptions: {
            ssl: {
                ssl: true,
                cert: fs.readFileSync(path.resolve(__dirname, 'ca-certificate.crt')).toString()
            }
        }
    }
    
    const con = mysql.createConnection(MYSQL_CONF)
    con.connect((err, result) => {
        if (err) {
            throw new Error(err)
            return
        } else {
            console.log('Successfully connecting with the database')
        }
    });
    

    This time it ends up with the error massage:
    Error: Error: ERACCESSDENIED_ERROR: Access denied for user “@‘58.84.111.221’ (using password: YES)

    I don’t know why i just copy and paste the password… And it shows the same error whenever locally or on the droplet…the funny thing is it didn’t even show up my username ”@'58.84.111.221’??? so can i ask do i need to have a user name?

    Please help me out…

    Boyu Zhang

    edited by bobbyiliev
    • Hi there @zhangboyu,

      This looks much better now as you are able to actually establish a connection.

      I think that the new problem that you are facing is that you are using username: and it should be user: in your connection string.

      Let me know how it goes.
      Regards,
      Bobby

Hi @zhangboyu, I have the same issue, During my development stage I established many connection pools to the database, after some time database firewall blocks my request, so set up a VPN and tried again and it will work.
Solution: Try some VPN

Submit an Answer