我刚刚从Openshift的市场安装了铁工工具 - 尝试了一个hello-world nodejs工作者,试图在Openshift上连接到MySQL数据库并且尝试被拒绝。 [顺便说一句,我可以通过MySQL工作台使用相同的凭据,通过端口转发连接到数据库]。我还用SSH来获取环境信息
env | grep OPENSHIFT_MYSQL
并使用主机和端口。
尝试在worker中创建基本连接并收到以下结果(实际配置值已更改):
my config: {"host":"111.11.nnn.nnn","port":3306,"user":"myapp","pass":"xxxxxxxxxxx","db":"app_db"}
about to make DB connection
We got an error connection to the DB: {"code":"ECONNREFUSED","errno":"ECONNREFUSED","syscall":"connect","fatal":true}
我认为连接不是由数据库拒绝,而是由防火墙/环境本身拒绝,因为我可以通过其他方式连接。建议?
仅供参考 - 代码:
var mysql = require('mysql');
// variables specific to your ironworker environment
var iron_helper = require('node_helper');
var params = iron_helper.params;
var task_id = iron_helper.task_id;
var config = iron_helper.config;
console.log('my config: ' + JSON.stringify(config));
console.log('about to make DB connection');
var connection = mysql.createConnection('mysql://'+config.user+':'+config.pass+'@'+config.host+':'+config.port+'/'+config.db);
var query = "select count(*) from reservations;";
connection.query( query, function(err, callResults){
if (err) {
console.log("We got an error connection to the DB: " + JSON.stringify(err));
}
else {
console.log("We got a result: " + JSON.stringify(callResults));
}
connection.destroy();
});