Error: connect ETIMEDOUT while connecting to MySQL

I am trying to connect to my MySQL database in node.js. But I get a timeout error when trying to connect to it. Here is my code:

var mysql = require('mysql');

var pool  = mysql.createPool({
  connectionLimit : 50,
  acquireTimeout :  100000,
  connectTimeout :  100000,
  host            : 'My hostname',
  user            : 'My user',
  password        : 'My password',
  database        : 'epiz_22678560_maindata'
});

pool.query('SELECT 1 + 1 AS solution', function (error, results, fields) {
  if (error) throw error;
  console.log('The solution is: ', results[0].solution);
});

You don’t need to care about what I am doing in the query. It’s just a test. I tried both the pool method (see above) and the standard one. I’ve read the knowledge base about MySQL connection errors, but the timeout isn’t there, and I tried all the procedures there (checking all the config data). I have everything correct

I even tried some website database connection testers (I know that it is dangerous, but I have some verified ones), all resulted in a connection error.

Could you please help me? I can give any more information I have. Thank you for your help, I appreciate that there is support even for free hosting.

You have read knowledge base bad, just wrong article

Oh thanks, I didn’t see that part. But it’s bad that I can only connect using php when I can’t use it :(. A bit offtopic, bit could anyone please help me to transform javascript to php? I heard about it, but the http-post and everything is complicated

@YeapGuy said:
Oh thanks, I didn’t see that part. But it’s bad that I can only connect using php when I can’t use it :(. A bit offtopic, bit could anyone please help me to transform javascript to php? I heard about it, but the http-post and everything is complicated

What are you trying to build here? Where is this Node.js code going to live?

Also, I would like to remind you that InfinityFree provides a website hosting service, not a database hosting service.

I am building a tracker for one game. It takes the data from the game’s API and it should upload them to a database (MySQL). I tried this but it doesn’t work. PHP should work, but many programmers can’t use it (me)

@YeapGuy said:
I am building a tracker for one game. It takes the data from the game’s API and it should upload them to a database (MySQL). I tried this but it doesn’t work. PHP should work, but many programmers can’t use it (me)

Maybe you could write a PHP script on here which takes the data submitted and stores it in the database, and have your Node.js script talk to the PHP script.

However, keep in mind that InfinityFree only provides website hosting, not database hosting. I can pretty much guarantee you that you’re going to run into trouble if you try and do something which is not a website (like a data storage/collection system).

It is for the website, I’ll show the data on it

Since you’re talking about API, shouldn’t there any code sample in Google to see (for PHP version)?

Add: does “cannot use” means the code isn’t working?

Okay, I figured it out with PHP, but I can’t even connect to that, because it’s blocked for “external applications” too :neutral: . Why are you blocking access even to a simple PHP file? How am I supposed to pass the data from somewhere to the website?! I am forced to use a different webhoster now.

It’s website hosting, not API, database or whatever else hosting, it’s not okay to use it like that.

You can try use Cloudflare, as I know some parts of security system disabling so you can do some requests, however you’re still can be blocked for things like that.

@YeapGuy said:
Okay, I figured it out with PHP, but I can’t even connect to that, because it’s blocked for “external applications” too :neutral: . Why are you blocking access even to a simple PHP file? How am I supposed to pass the data from somewhere to the website?! I am forced to use a different webhoster now.

No, you’re not forced to use a different webhoster. You’re forced to use an application hoster or database hoster, not a webhoster. A webhoster is for websites, not data collection services.

If you have an external data collection service (I believe Google’s Firebase has a free tier) you can upload a website here which displays the data from the data storage service. Because that’s a website, and that’s what we can provide hosting for.