Reputation: 152
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?
Upvotes: 6
Views: 11594
Reputation: 1723
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
});
Upvotes: 5