【发布时间】:2016-03-22 00:53:35
【问题描述】:
我不久前设置了我的数据库服务器,并让我的节点 Web 服务器正常连接到它。在我的 dbcommon.js 文件中,我有以下内容。
var credentials = require('./db_access');
var mysql = require('mysql');
//Use this function to grab a thread from the db thread pool and connect to the db. Then it queries the db with the sql statement passed to it.
exports.executeStatement = function(pool, sql, callback){
pool.getConnection(function(err, connection){
if (err) {
callback(err);
}
else {
connection.query(sql, function(err, results, fields) {
if(!err){
connection.release();
callback(results);
} else {
connection.release();
callback(err);
}
});
}
});
};
//TODO - Own class
exports.pool = mysql.createPool({
connectionLimit: 100,
host: "host_url_goes_here",
user: credentials.user,
password: credentials.pass,
database: "bxdb",
dateStrings: true //Instead of converting to a JS Date object, return as a string
});
在我的 db_access.js 文件中,我有
var user = 'user123';
var pass = 'password123'; //not real
module.exports = user;
module.exports = pass;
奇怪的是,在我决定尝试使用 IAM 密钥来访问数据库之前,它工作得非常好。但是我无法让它工作(访问被拒绝错误)所以我改回我现在的状态,但我仍然收到访问被拒绝错误。然而,我的朋友拥有相同的代码仍然能够访问数据库而不会出现此错误。我很迷茫。 db_access.js 文件与 dbcommon.js 文件位于同一文件夹中。
另外,我目前访问数据库的方式是否相当安全?还是我应该以另一种方式来做? (db_access.js 文件永远不会推送到 git,它只在本地可用)
【问题讨论】:
标签: mysql node.js amazon-web-services access-denied