'Node - MySQL Connection Error. Unique to Node

I have a mysql 8.0.27 server running locally on a Mac OSX 10.15. I'm working on a node.js API for the database. When I try to build the server I get this error.

if (error) throw error;
               ^

Error: connect ECONNREFUSED ::1:3306
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
  errno: -61,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '::1',
  port: 3306,
  fatal: true
}

I think it's isolated to node because I'm also using a jupyter notebook with python to build the database and pre-populate it with data. The same connection configuration easily connects to the db. Same user.

I've tried mysql and mysql2 npm packages. At this point, I need some help with directions I should go in troubleshooting.



Solution 1:[1]

First, use 127.0.0.1 instead of localhost.

then you'll see the below error;

  code: 'ER_NOT_SUPPORTED_AUTH_MODE',
  errno: 1251,
  sqlMessage: 'Client does not support authentication protocol requested by server; consider upgrading MySQL client',

To fix that use the below SQL command;

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password' and then flush privileges

this worked for me

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lahiru Cooray