我正在Google App Engine中设置一个NodeJS后端,当我尝试连接到SQL Cloud(使用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)
答案 0 :(得分:1)
Connect ENOENT表示系统无法连接到mysql,因为其路径不正确。 使用指定的代码更新models / 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 =新的Sequelize(“数据库”,用户名,密码,{
host: "localhost",
dialect: "mysql",
logging: function () {},
pool: {
max: 5,
min: 0,
idle: 10000
},
dialectOptions: {
socketPath: "/var/run/mysqld/mysqld.sock"
},
define: {
paranoid: true
}
});