[SequelizeConnectionRefusedError]:连接ECONNREFUSED 127.0.0.1:3306

时间:2020-10-04 17:20:49

标签: javascript mysql server sequelize-cli

嗨,我是Sequelize ORM的新手。我正在学习一些教程,并且在动手操作时,我面临着将MySQL数据库与服务器连接的问题。

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"
  }
}

谁能告诉我为什么我无法连接到数据库?

0 个答案:

没有答案