I'm following a Node.js and MySQL connection example, but running the script produces an ECONNREFUSED error for both ::1:3306 and 127.0.0.1:3306. What does this error mean, and what should I check to get the connection working?
2 Answers
ECONNREFUSED means your Node.js process reached the local machine, but nothing accepted the connection on port 3306. Check that MySQL or MariaDB is actually running and configured to listen on that port. You can also test it directly with `mysql -h 127.0.0.1 -P 3306 -u -p`. If the database uses a different port or host, update your Node.js connection settings accordingly.
The addresses in the error are both loopback addresses: `::1` is IPv6 localhost and `127.0.0.1` is IPv4 localhost. This usually isn’t a username or password problem—the connection fails before authentication. If MySQL is running but still refuses the connection, check whether it is listening for TCP connections rather than only using a local socket. Also, if MySQL is in Docker, `localhost` from a Node.js container refers to the Node container itself; use the database service name instead.

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically