简体   繁体   中英

ETIMEDOUT while connecting remote mysql database from node.js app on heroku server

Example of the code I use:

const connection = mysql.createPool({
    host: process.env.NEXT_DB_HOST, //*******.timeweb.ru
    database: process.env.NEXT_DB_DATABASE, //c*****_tech
    user: process.env.NEXT_DB_USER, //c*****_tech
    password: process.env.NEXT_DB_PASSWORD, //******
    waitForConnections: true,
    connectTimeout: 100000,
    connectionLimit: 10,
    queueLimit: 0
});

connection.query(
    "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE'",
    (err, results, fields) => {
         if(err) console.log(err);
         console.log(results);
         console.log(fields);
    }
);

All vars are added in heroku. Also the domain is added to timeweb panel as "Access db point". I know that heroku has dinamic IP, so how can I connect remote db?

Timeweb use only static IP-address for connecting, but heroku has dinamic. It's better to change hosting, for node.js apps it could be any VPS such as Timeweb.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM