CodexBloom - Programming Q&A Platform

scenarios connecting to MySQL database with Sequelize in Node.js - `ConnectionRefusedError`

👀 Views: 0 đŸ’Ŧ Answers: 1 📅 Created: 2025-06-27
node.js sequelize mysql database-connection JavaScript

Does anyone know how to I've searched everywhere and can't find a clear answer. I'm trying to connect my Node.js application to a MySQL database using Sequelize, but I'm consistently getting a `SequelizeConnectionRefusedError`. I've confirmed that the database server is running and that I'm using the correct credentials, but the behavior continues. The full behavior message is: ``` UnhandledPromiseRejectionWarning: SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306 ``` Here's the code I'm using to initialize the Sequelize connection: ```javascript const { Sequelize } = require('sequelize'); const sequelize = new Sequelize('mydatabase', 'myuser', 'mypassword', { host: '127.0.0.1', dialect: 'mysql', logging: false, }); async function testConnection() { try { await sequelize.authenticate(); console.log('Connection has been established successfully.'); } catch (behavior) { console.behavior('Unable to connect to the database:', behavior); } } testConnection(); ``` I've also tried checking my MySQL configuration in `my.cnf`, ensuring that `bind-address` is set to `0.0.0.0` to allow connections from any IP. I restarted the MySQL service after making this change. Additionally, I've verified that there are no firewall rules blocking access to port 3306. I'm running the latest versions of Node.js (v16.13.0) and Sequelize (v6.6.2). Any ideas on what might be causing this connection scenario? Is there something specific in the Sequelize setup that I might be missing? For context: I'm using Javascript on macOS. Any feedback is welcome!