Can't connect to MySQL with Sequelize

前端 未结 1 1575
我在风中等你
我在风中等你 2021-01-03 05:58

I consistently get a SequelizeConnectionRefusedError when trying to connect to a MySQL database on my server.

The login credentials are correct, the por

相关标签:
1条回答
  • 2021-01-03 06:52

    I tried to connect to the database directly with the MySQL module as well, but that gave me the same error. When looking for solutions to the same problem, but related to the MySQL module rather than Sequelize, I found this: connect ECONNREFUSED - node js , sql.

    What I needed was to supply the mysql module with a socketPath key. Here's how I changed my code to make it work:

    var sequelize = new Sequelize("database", username, password, {
        host: "localhost",
        dialect: "mysql",
        logging: function () {},
        pool: {
            max: 5,
            min: 0,
            idle: 10000
        },
        dialectOptions: {
            socketPath: "/var/run/mysqld/mysqld.sock"
        },
        define: {
            paranoid: true
        }
    });
    
    0 讨论(0)
提交回复
热议问题