6

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?

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? 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. Commented Jul 20, 2017 at 18:33

1 Answer 1

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.org',
    username: 'myusername',
    password: 'mypassword',
    connectTimeout: 30000
});
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your answer. I tried that, but it still gives me the 'ETIMEDOUT'-error. Any idea why that would be?
Are you able to connect to your db from the shell?
no I wasn't, I have contacted the hosting service and apparently it is not possible to connect to this webserver from an external source due to a firewall. I am going to move the database to another server. Thanks for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.