I try to make a simple connection to an online mysql database on a node.js server. This is my code:
var mysql = require('mysql');
var con = mysql.createConnection({
host: 'example.org',
username: 'myusername',
password: 'mypassword'
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
Whenever I run this server I get the error: "connect ETIMEDOUT".
I am a 100% sure my credentials are correct and I also changed the privileges of the user in phpmyadmin (I gave this user all possible privileges).
I run the server locally, I am not sure if this has anything to do with it.
My questions are: - Why is it timing out? - And how can I connect to this database?
Seemingly, this is related to your DataBase server.
Though, you can try to extend the timeout default, by passing a longer timeout value. (Default is 10000).
Just do:
var con = mysql.createConnection({
host: 'example.org',
username: 'myusername',
password: 'mypassword',
connectTimeout: 30000
});
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.