【发布时间】:2019-03-05 21:36:26
【问题描述】:
我有一个 NodeJs 应用程序和 MySQL 数据库。
我已经在谷歌云中部署了 nodejs 应用程序并在google cloud 中创建了 MySQL 数据库并连接到 nodejs 应用程序
我能够成功部署应用程序,但应用程序无法连接到云 mysql dayabase。
但是当我尝试从本地 mysql 工作台连接云 mysql 时,它已成功连接到数据库。我可以从本地 nodejs 应用程序连接云 mysql 数据库
但我无法从已部署的 nodejs 应用程序连接到云 mysql db
错误 Database is not connectedError: connect ETIMEDOUT
Db.js
var mysql = require('mysql');
var PropertiesReader = require('properties-reader');
var properties = PropertiesReader('./db.properties');
var connection = mysql.createConnection({
connectionLimit : properties.get('pool'),
host: properties.get('hostname'),
user: properties.get('username'),
password: properties.get('password'),
database: properties.get('dbname')
});
connection.connect(function (err) {
if (!err) {
console.log("Database is connected");
} else {
console.log("Database is not connected" + err);
}
}
);
module.exports = connection;
app.yaml
runtime: nodejs
env: flex
【问题讨论】:
-
所以没有错误?
-
是的,它有错误
-
您是否在 app.yaml 文件中添加了环境变量和 beta_settings 部分,详见此处:cloud.google.com/appengine/docs/flexible/nodejs/…?
标签: mysql node.js google-app-engine google-cloud-platform