Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node 17.4, MySQL Server 8.0, Mac OS Monterey, ECONNREFUSED with error code -61, ::1:3306 #2547

Closed
bhutchins1a opened this issue Feb 1, 2022 · 5 comments
Labels

Comments

@bhutchins1a
Copy link

No description provided.

@bhutchins1a
Copy link
Author

bhutchins1a commented Feb 1, 2022

Hi, Guys.
Ran into an issue trying to connect with node V 17.4. Plugin is mysql_native_password, user has a password.

JS:

var mysql = require('mysql');

var connection = mysql.createConnection({
	host: 'localhost',
	user: 'root',
	password: 'password',
	database: 'join_us'
});

Get the following error trace:

/Users/david/Projects/mysql_bootcamp/faker/app.js:13
  if (error) throw error;
             ^

Error: connect ECONNREFUSED ::1:3306
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1157:16)
    --------------------
    at Protocol._enqueue (/Users/david/Projects/mysql_bootcamp/faker/node_modules/mysql/lib/protocol/Protocol.js:144:48)
    at Protocol.handshake (/Users/david/Projects/mysql_bootcamp/faker/node_modules/mysql/lib/protocol/Protocol.js:51:23)
    at Connection.connect (/Users/david/Projects/mysql_bootcamp/faker/node_modules/mysql/lib/Connection.js:116:18)
    at Object.<anonymous> (/Users/david/Projects/mysql_bootcamp/faker/app.js:10:12)
    at Module._compile (node:internal/modules/cjs/loader:1097:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1149:10)
    at Module.load (node:internal/modules/cjs/loader:975:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47 {
  errno: -61,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 3306,
  fatal: true
}

After agonizing for a while, I couldn't understand the ::1:3306 part of the error message. Changed 'localhost' in the connection object to 127.0.0.1 and it worked. This is with node.js 17.4

Downgraded node.js to 16.X and kept the host in the connection object as 'localhost' and it worked fine.

Any idea what changed between node.js 16.X and 17.4 that would affect the mysql package?

P.S.: There's no binding address in the MySQL server config file.

@dougwilson
Copy link
Member

Hi, sorry you had trouble. How TCP connections resolve domain name and the errors is all handled by Node.js, which is why changing the Node.js version changes behavior. This module is not actually involved in that behavior.

@bhutchins1a
Copy link
Author

Hi, sorry you had trouble. How TCP connections resolve domain name and the errors is all handled by Node.js, which is why changing the Node.js version changes behavior. This module is not actually involved in that behavior.

Thanks for looking at it so quickly, Doug.

@dougwilson
Copy link
Member

No problem. I also checked and in Node.js 17.0 changelog says that the DNS resolution no longer puts IPv4 addresses first, instead they are returned as it comes from the OS. Probably the OS hosts file has ::1 above 127.0.0.1, so Node.js+ will resolve it as IPv6 ::1 instead of 127.0.0.1 on that system.

@bhutchins1a
Copy link
Author

Thanks for following up. The Node.js changelog makes it make sense now (awkward sentence structure).

👍👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants