0

I have a problem with sequelize, which is not letting me connect to a database that I have, it is strange since I can connect from the shell with the same credentials.

Error:

ConnectionRefusedError [SequelizeConnectionRefusedError]: connect ECONNREFUSED 127.0.0.1:3306
    at ConnectionManager.connect (re/node_modules/sequelize/lib/dialects/mysql/connection-manager.js:92:17)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async ConnectionManager._connect (re/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:220:24)
    at async re/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:174:32
    at async ConnectionManager.getConnection (re/node_modules/sequelize/lib/dialects/abstract/connection-manager.js:197:7)
    at async re/node_modules/sequelize/lib/sequelize.js:301:26
    at async Sequelize.authenticate (re/node_modules/sequelize/lib/sequelize.js:453:5) {
  parent: Error: connect ECONNREFUSED 127.0.0.1:3306
      at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1195:16) {
    errno: -111,
    code: 'ECONNREFUSED',
    syscall: 'connect',
    address: '127.0.0.1',
    port: 3306,
    fatal: true
  },
  original: Error: connect ECONNREFUSED 127.0.0.1:3306
      at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1195:16) {
    errno: -111,
    code: 'ECONNREFUSED',
    syscall: 'connect',
    address: '127.0.0.1',
    port: 3306,
    fatal: true
  }
}

Code:

import { Sequelize } from 'sequelize'

// connect to mysql database
export const db = new Sequelize( 'db_restaurant', 'root', '1234', {
    host: 'localhost',
    dialect: 'mysql',
})

Class server.ts

async dbConnection () {
        try {
            await db.authenticate();
            console.log( 'Connection to the database has been established successfully.' );
        }
        catch ( error : any ) {
            console.log( error );
        }
    }

Shell: enter image description here

Package:

{
  "name": "re",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/cors": "^2.8.12",
    "@types/express": "^4.17.13",
    "@types/node": "^17.0.38",
    "tslint": "^6.1.3",
    "typescript": "^4.7.2"
  },
  "dependencies": {
    "cors": "^2.8.5",
    "dotenv": "^16.0.1",
    "express": "^4.18.1",
    "mariadb": "^3.0.0",
    "mysql2": "^2.3.3",
    "sequelize": "^6.20.1"
  }
}

MySQL Workbench: enter image description here

also install mariaDB from xampp to test that it is mysql workbench, however it didn't work either, but from the shell I was able to connect to xampp, obviously I tried to change the port to 3307 or another, but it didn't work either

I am developing this in a windows development environment

0 Answers0