NodeJS - 连接到本地Mysql数据库

时间:2015-11-27 17:25:11

标签: mysql database node.js sequelize.js

我正在尝试为我的节点应用程序创建一个mysql数据库连接,并运行 Instabug.DEBUG = true; instabug = Instabug.initialize(this) .setAnnotationActivityClass(InstabugAnnotationActivity.class) .setShowIntroDialog(true, PSTimelineActivity.class) .enableEmailField(true, false) .setEnableOverflowMenuItem(true) .setDebugEnabled(true) .setCommentRequired(true) .setPostFeedbackMessage(getString(titleID) + getString(R.string.feedback_confirmation_subtitle)) .setPostBugReportMessage(getString(titleID) + getString(R.string.feedback_confirmation_subtitle)) //TODO will be the post report message, random from array .setCommentFieldHint("Please describe what went wrong") 来测试连接是否有效。记录到我的控制台的响应为sequelize.authenticate().then(function(errors) { console.log(errors) }); Executing (default): SELECT 1+1 AS result undefined部分让我认为连接不起作用或找不到任何数据库。我似乎无法弄清楚这一点。我想通过Sequel Pro创建数据库并通过Socket连接到undefined,我可以使用相同的凭据连接我的Node应用程序。我是否需要在我的应用程序中为数据库创建文件而不使用Sequel Pro数据库?

控制器文件(创建连接的位置):

localhost

ann-model.js(我的桌子正在定义中):

var Sequelize = require('sequelize');
var sequelize = new Sequelize('synotate', 'root', '', {
    host:'localhost',
    port:'3306',
    dialect: 'mysql'
});

sequelize.authenticate().then(function(errors) { console.log(errors) });

var db = {}

db.Annotation = sequelize.import(__dirname + "/ann-model");

db.sequelize = sequelize;
db.Sequelize = Sequelize;

module.exports = db;

database for localhost

1 个答案:

答案 0 :(得分:2)

试试这个,Executing (default): SELECT 1+1 AS result意味着一切都好吗

 sequelize
        .authenticate()
        .then(function(err) {
            if (!!err) {
                console.log('Unable to connect to the database:', err)
            } else {
                console.log('Connection has been established successfully.')
            }
        });

但我不知道你在哪里undefined