0

I'm creating a website which stores data from client-side. And, I'm trying to connect to MySQL from that website using the following code (example),

let mysql = require('mysql');
let conn = mysql.createConnection({
  user: 'root',
  host: process.env.MYIP, // my laptop ipv4 address
  database: process.env.MYDB,
  password: process.env.PASS
});
conn.connect(err => {
  if(err)
    console.log(err);
  else
    console.log('Success!');
});

BTW, I'm a beginner in networking, so I couldn't guess the reason behind these errors.

In logs, I'm getting "...error ETIMEDOUT...". However, my credentials are correct (as it doesn't throws error: ECONNREFUSED, which it'd thrown earlier). But, I can't connect to MySQL. Note that, I'm using XAMPP to on Apache and MySQL server.

I've tried:

  • setting connectTimeout
  • trying a createPool
  • command: mysql> GRANT ALL ON fooDatabase.* TO fooUser@'1.2.3.4' IDENTIFIED BY 'my_password';

Why it is so?

The whole error log:

Error: connect ETIMEDOUT

    at Connection._handleConnectTimeout (/***/pnpm-volume/******/node_modules/.registry.npmjs.org/mysql/2.18.1/node_modules/mysql/lib/Connection.js:409:13)

    at Object.onceWrapper (events.js:284:20)

    at Socket.emit (events.js:196:13)

    at Socket._onTimeout (net.js:432:8)

    at listOnTimeout (internal/timers.js:531:17)

    at processTimers (internal/timers.js:475:7)

    --------------------

    at Protocol._enqueue (/***/pnpm-volume/*******/node_modules/.registry.npmjs.org/mysql/2.18.1/node_modules/mysql/lib/protocol/Protocol.js:144:48)

    at Protocol.handshake (/***/pnpm-volume/*******/node_modules/.registry.npmjs.org/mysql/2.18.1/node_modules/mysql/lib/protocol/Protocol.js:51:23)

    at Connection.connect (/***/pnpm-volume/*******/node_modules/.registry.npmjs.org/mysql/2.18.1/node_modules/mysql/lib/Connection.js:116:18)

at Object.<anonymous> (

:6)

    at Module._compile (internal/modules/***/loader.js:759:30)

    at Object.Module._extensions..js (internal/modules/***/loader.js:770:10)

    at Module.load (internal/modules/***/loader.js:628:32)

    at Function.Module._load (internal/modules/***/loader.js:555:12)

    at Function.Module.runMain (internal/modules/***/loader.js:826:10)

    at internal/main/run_main_module.js:17:11 {

  errorno: 'ETIMEDOUT',

  code: 'ETIMEDOUT',

  syscall: 'connect',

  fatal: true

}
danblack
  • 12,130
  • 2
  • 22
  • 41
vrintle
  • 5,501
  • 2
  • 16
  • 46
  • Are you able to connect to MySQL via the terminal? Do you need to tell it which port to use? https://stackoverflow.com/questions/40868653/etimedout-error-when-querying-mysql-database – Alan P. Jun 06 '20 at 04:50
  • @AlanP. yes I'm able to connect to mysql via terminal. I think it either uses 3306 or 3307 port, both of them causing the same error, when I added `port: 330x` in config. – vrintle Jun 06 '20 at 05:14
  • Ok read that link I shared. I think you have to pass the port to createConnection – Alan P. Jun 06 '20 at 05:16
  • @AlanP. I edited my comment a bit late, btw are u aware of glitch.com, that could make it easier to solve my issue? – vrintle Jun 06 '20 at 05:17
  • Also @AlanP., what is MAMP? Currently, I've started Apache and MySQL from Xampp. Is MAMP reuired? (see edit) – vrintle Jun 06 '20 at 05:21
  • WAMP is Windows, Apache, MySQL, PHP. MAMP is Mac, Apache, MySQL, PHP. – Alan P. Jun 06 '20 at 05:37

0 Answers0