【问题标题】:Getting "Unhandled rejection SequelizeConnectionError: connect ENOENT" when connecting to SQL Cloud连接到 SQL Cloud 时出现“未处理的拒绝 SequelizeConnectionError:连接 ENOENT”
【发布时间】:2019-06-12 12:57:15
【问题描述】:

我正在 Google App Engine 中设置 NodeJS 后端,当我尝试连接到 SQL 云(使用 sequelize + postgres)时,我收到了这个错误:

Unhandled rejection SequelizeConnectionError: connect ENOENT /cloudsql/tar:us-central1:dbpointofsales/.s.PGSQL.5432
    at connection.connect.err (/home/mf/backend/node_modules/sequelize/lib/dialects/postgres/connection-manager.js:182:24)
    at Connection.connectingErrorHandler (/home/mf/backend/node_modules/pg/lib/client.js:163:14)
    at Connection.emit (events.js:182:13)
    at Socket.reportStreamError (/home/mf/backend/node_modules/pg/lib/connection.js:71:10)
    at Socket.emit (events.js:182:13)
    at emitErrorNT (internal/streams/destroy.js:82:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
    at process._tickCallback (internal/process/next_tick.js:63:19)

【问题讨论】:

    标签: google-cloud-platform google-cloud-sql


    【解决方案1】:

    Connect ENOENT 表示系统无法连接到mysql,因为它的路径不正确。 使用指定的代码更新模型 / index.js 文件。要查找 mysql 套接字的路径,请转到此处的文件 /etc/mysql/my.cnf(此路径可能取决于您的服务器)。例如,/etc/my.cnf。在这里,您将找到套接字的路径。

    请验证,它需要管理员权限(ubuntu 上的 sudo)。 确认登录凭据正确,端口已打开。

    您必须验证设置连接,然后您可以尝试确认连接。

    测试连接

    续集

    .authenticate()

    .then(() => {

    console.log('Connection has been established successfully.');
    

    })

    .catch(err => {

    console.error('Unable to connect to the database:', err);
    

    });

    带有密钥socketPath的模块mysql。

    var sequelize = new Sequelize("数据库", 用户名, 密码, {

    host: "localhost",
    
    dialect: "mysql",
    
    logging: function () {},
    
    pool: {
    
        max: 5,
    
        min: 0,
    
        idle: 10000
    
    },
    
    dialectOptions: {
    
        socketPath: "/var/run/mysqld/mysqld.sock"
    
    },
    
    define: {
    
        paranoid: true
    
    }
    

    });

    【讨论】: