Openshift 上的 NodeJS Express + MySQL 应用不是 运行

NodeJS+ Express + MySQL app not running on Openshift

我有一个可以成功部署但无法启动的 nodejs 应用程序。当我查看日志文件时,我一直收到此错误:

Warning: connect.session() MemoryStore is not
designed for a production environment, as it will leak
memory, and will not scale past a single process.
Tue Mar 29 2016 05:48:11 GMT-0400 (EDT): Node server started on 127.8.221.129:8080 ...
Server on port : 8080
Tue Mar 29 2016 05:48:11 GMT-0400 (EDT): Node server stopped.
/var/lib/openshift/56f90f110c1e663f390001df/app-root/runtime/repo/models/user.js:14
    throw err;
    ^
Error: getaddrinfo ENOTFOUND mysql://127.8.221.130:3306/ mysql://127.8.221.130:3306/:3306
    at errnoException (dns.js:26:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:77:26)
    --------------------
    at Protocol._enqueue (/var/lib/openshift/56f90f110c1e663f390001df/app-root/runtime/repo/node_modules/mysql/lib/protocol/Protocol.js:141:48)
    at Protocol.handshake (/var/lib/openshift/56f90f110c1e663f390001df/app-root/runtime/repo/node_modules/mysql/lib/protocol/Protocol.js:52:41)
    at Connection.connect (/var/lib/openshift/56f90f110c1e663f390001df/app-root/runtime/repo/node_modules/mysql/lib/Connection.js:123:18)
    at Object.<anonymous> (/var/lib/openshift/56f90f110c1e663f390001df/app-root/runtime/repo/models/user.js:12:13)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (internal/module.js:16:19)
    at Object.<anonymous> (/var/lib/openshift/56f90f110c1e663f390001df/app-root/runtime/repo/routes/users.js:3:13)
    at Module._compile (module.js:413:34)
    at Object.Module._extensions..js (module.js:422:10)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)

这是MySQL连接码(密码是隐藏的,不过我用的是MySQL墨盒提供的那个,还有用户):

var connection = mysql.createConnection({
host     : 'mysql://' + process.env.OPENSHIFT_MYSQL_DB_HOST + ':' + process.env.OPENSHIFT_MYSQL_DB_PORT + '/',
user     : 'adminbL38x6k',
password : '********',
database : 'addressbook'
});

 connection.connect( function(err){
if (err){ 
    throw err;
}
else {
    console.log('Connected');
}
 });

我也在使用 PHPmyAdmin 来创建 tables/managing 数据库。有任何想法吗?我很绝望...谢谢!

连接错误显示两个连接字符串(ENOTFOUND mysql://127.8.221.130:3306/ mysql://127.8.221.130:3306/:3306),根据 mysql node.js 驱动程序的 documentation,主机和端口应单独提供或在单个连接字符串,我推荐:

var connection = mysql.createConnection({
host     : process.env.OPENSHIFT_MYSQL_DB_HOST,
port     : process.env.OPENSHIFT_MYSQL_DB_PORT,
user     : 'adminbL38x6k',
password : '********',
database : 'addressbook'
});

...或连接字符串方式:

var connection = mysql.createConnection(process.env.OPENSHIFT_MYSQL_DB_URL + 'addressbook');