2 votes

Error: connect ETIMEDOUT

I am trying to connect through nodejs to mysql, and every time I run it I get the following error:

Error: connect ETIMEDOUT ipservidor:3306
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1129:14)
--------------------
at Protocol._enqueue (C:\Users\Eze\Desktop\mysqltest\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at Protocol.handshake (C:\Users\Eze\Desktop\mysqltest\node_modules\mysql\lib\protocol\Protocol.js:51:23)
at Connection.connect (C:\Users\Eze\Desktop\mysqltest\node_modules\mysql\lib\Connection.js:119:18)
at Object.<anonymous> (C:\Users\Eze\Desktop\mysqltest\app.js:11:5)
at Module._compile (internal/modules/cjs/loader.js:971:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1011:10)
at Module.load (internal/modules/cjs/loader.js:822:32)
at Function.Module._load (internal/modules/cjs/loader.js:730:14)
at Function.Module.runMain (internal/modules/cjs/loader.js:1051:12)
at internal/main/run_main_module.js:16:11 {
errno: -4039,
code: 'ETIMEDOUT',
syscall: 'connect',
address: 'ipservidor',
port: 3306,
fatal: true
}
The solution is:  undefined

This is my code:

const mysql = require('mysql');
const con = mysql.createConnection({
  host: 'ipservidor',
  user: 'user',
  password: 'pass',
  database: 'database',
  connectTimeout: 30000
});
con.connect();

con.query('SELECT * from fichar', function(err, rows, fields) {
  if(err) console.log(err);
  console.log('The solution is: ', rows);
  con.end();
});

I have checked that the port is open for the connection, the firewall is disabled on the server (it is a test server) and I can not connect.

Any ideas?

1 votes

Can you connect from the terminal or any other manager?

1 votes

From the server itself I can connect without any problem @EugeniBejan

1 votes

Have you checked that the server listens on the public ip? And not only localhost

2voto

Sphere Points 83

I have found the solution here: https://mariolurig.com/coding/connect-remotely-mysql-database-amazon-ec2-server/

Thanks to Eugeni!

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X