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?
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.
Click below to sign up and get $100 of credit to try our products over 60 days!
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
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:Let me know how it goes! Regards, Bobby