admin管理员组

文章数量:1379351

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',
    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?

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',
    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?

Share Improve this question edited Jul 20, 2017 at 17:25 Siebrand Romeyn asked Jul 20, 2017 at 14:58 Siebrand RomeynSiebrand Romeyn 1521 gold badge1 silver badge9 bronze badges 2
  • Error: connect ETIMEDOUT in the connect callback indicates that the connection to the mysql server could not be established. Are you sure that the host you entered points to an ip the mysql server is listening to and that mysql ist listening to the standard port? – t.niese Commented Jul 20, 2017 at 17:36
  • @t.niese At 'host' I put the URL of the webserver I host the MySQL database on. I also tried replacing the URL with an IP address but that didn't work either. – Siebrand Romeyn Commented Jul 20, 2017 at 18:33
Add a ment  | 

1 Answer 1

Reset to default 5

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',
    username: 'myusername',
    password: 'mypassword',
    connectTimeout: 30000
});

本文标签: javascriptNodejs MySQL database connectiontime out (ETIMEDOUT)Stack Overflow