简体   繁体   中英

[SequelizeConnectionRefusedError]: connect ECONNREFUSED 127.0.0.1:3306

Hi I am new with Sequelize ORM. I am following some tutorial and while hands-on, I am facing the problem in connecting the MySQL database with server.

ConnectionRefusedError [SequelizeConnectionRefusedError]: connect ECONNREFUSED 127.0.0.1:3306
    at ConnectionManager.connect (G:\projects\chatApp\node_modules\sequelize\lib\dialects\mysql\connection-manager.js:116:17)
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  parent: Error: connect ECONNREFUSED 127.0.0.1:3306
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16) {
    errno: 'ECONNREFUSED',
    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] (net.js:1141:16) {
    errno: 'ECONNREFUSED',
    code: 'ECONNREFUSED',
    syscall: 'connect',
    address: '127.0.0.1',
    port: 3306,
    fatal: true
  }
}

Serve.js

const { ApolloServer } = require('apollo-server')

const { sequelize } = require('./models')

const resolvers = require('./graphql/resolvers')
const typeDefs = require('./graphql/typeDefs')

const server = new ApolloServer({
    typeDefs,
    resolvers,
})

server.listen().then(({ url }) => {
    console.log(`🚀 Server ready at ${url}`)

    sequelize
        .authenticate()
        .then(() => console.log('Database connected!!'))
        .catch((err) => console.log(err))
})

config.json

{
  "development": {
    "username": "root",
    "password": "root",
    "database": "database_dev",
    "host": "127.0.0.1",
    "dialect": "mysql"
  }
}

Can anyone tell me why I am not able to connect to the database?

检查您正在使用的 mysql 端口,也许是 3307 ?

  1. run MySql installer
  2. reconfigure the MySql Server. it will work fine.

check this out

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM