Google App Engine具有云SQL使用quelize部署错误



我想将我的节点应用部署到应用程序引擎,并使用demelize for the Orm使用Cloud SQL MySQL,但是我在部署时会遇到以下错误,没有其他信息进行调试。p>我的yaml是(带有编辑的详细信息(:

env: flex
runtime: nodejs
env_variables:
  SQL_USER: -
  SQL_PASSWORD: -
  SQL_DATABASE: -
  INSTANCE_CONNECTION_NAME: -
  beta_settings:
  cloud_sql_instances: -

无法连接到SQL数据库:未定义 未接收错误{fileName: '/app/node_modules/sequelize/lib/dialects/mysql/connection-manager.js', 线:133, 行:19, 消息:'连接enoent/cloudsql/app:欧洲 - west1:db', 类型:" seqelizeconnectionerror", 堆: 'seqelizeconnectionError:连接enoent/cloudsql/app:europe-west1:db n at Promise.tap.tap.then.catch.err(/app/node_modules/seceelize/seceelize/lib/lib/dialect/dialects/mysql/mysql/mysql/connection-manager.js:19:133:19:133:133:119( n在trycatcher(/app/node_modules/bluebird/js/release/release/util.js:16:23) n at Promise._settletlepromisefromisefromhandler(/app/node_modules/node_modules/bluebird/bluebird/js/release/release/promise.js:512:31:31:312:312:31( n在Promise._settlePromise(/app/node_modules/bluebird/js/release/promise.js:569:18(at Promise._settlePromise0(/app/node_modules/bluebird/js/release/release/promise.js:6114(:10( n在Promise._SettlePromises(/app/node_modules/bluebird/js/release/promise.js:690:18) n at_drainqueuestep(/app/node_modules in:12( n在_drainqueue(/app/node_modules/bluebird/js/release/async.js:131:9) ainsync._drainqueues(/app/node_modules/bluebird/js/release/release/async/async.js:147 at async._drainqueues(/:5( n在agiper.async.drainqueues [as _onimmediate](/app/node_modules/bluebird/js/release/release/ashync.js:17:17:14:14:14) n runcallback(timers.js:705:18(在tryonimediate(Timers.js:676:5( n processimmediate(Timers.js:658:5(', 参数:未定义}

ORM代码:

const sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASS, {
      dialect: 'mysql',
      host: '/cloudsql/app:europe-west1:db',
      pool: {
          max: 5,
          min: 0,
          acquire: 30000,
          idle: 10000
      },
      dialectOptions: {
          socketPath: '/cloudsql/app:europe-west1:db'
      },
      logging: false
    });

首先,您的app.yaml不应缩进beta_settings:

...
  INSTANCE_CONNECTION_NAME: <YOUR_INSTANCE_CONNECTION_NAME>
beta_settings:
  cloud_sql_instances: <YOUR_INSTANCE_CONNECTION_NAME>

接下来,UNIX插座位于/cloudsql/<YOUR_INSTANCE_CONNECTION_NAME>。您应该使用您在app.yaml中指定的环境变量以编程设置:

socketPath: util.format('/cloudsql/%s', process.env.INSTANCE_CONNECTION_NAME), // '/cloudsql/<YOUR_INSTANCE_CONNECTION_NAME>`

您还将SQL_USERSQL_PASSWORDSQL_DATABASE指定为app.yaml中的Env vars,但请致电process.env.DB_USERprocess.env.DB_PASSprocess.env.DB_NAME。如果您希望它们具有任何价值,则需要保持一致。

最后,续集在某种程度上不清楚如何最好地使用UNIX套接字-hostdialectOptions.socketPath可能不应该两个设置。从续集文档来看,我建议只使用socketPath

const sequelize = new Sequelize(process.env.DB_NAME, process.env.DB_USER, process.env.DB_PASS, {
      dialect: 'mysql',
      pool: {
          max: 5,
          min: 0,
          acquire: 30000,
          idle: 10000
      },
      dialectOptions: {
          socketPath: util.format('/cloudsql/%s', process.env.INSTANCE_CONNECTION_NAME),
      },
      logging: false
    });

相关内容

  • 没有找到相关文章

最新更新