【问题标题】:Contents of SQL export not executing properly with felixge/node-mysqlfelixge/node-mysql 无法正确执行 SQL 导出的内容
【发布时间】:2014-02-05 06:39:12
【问题描述】:

我从 MySQL Workbench 创建了一个 sql 数据库(所有表和视图)的导出。删除数据库 drop/create 行后,我可以通过 SQL 引擎运行导出文件的内容,一遍又一遍地重新创建表和视图,没有任何问题。

但是,当我尝试通过 felixge/node-mysql 填充文件内容时,出现语法错误。

是否有使用 node-mysql 处理这种模式的标准方法?

附件是我试图让 node-mysql 在数据库上执行的 SQL 文件的全部内容。无论数据库是空的还是已经有表,它都会失败。

SQL 文件: http://pastebin.com/YjuDbyEK

节点代码:

var db = new mysql.createConnection({
    host : 'localhost',
    user : 'root',
    password : 'admin',
    database : 'nps',
    multipleStatements : true
});

//Check for the SQL upgrade file and stuff the contents through node-mysql
fs.exists(setting.NPS_loadFile, function(exists) {
    if(exists){
        fs.readFile(setting.NPS_loadFile, 'utf-8', function(err, sql) {
            if (err) {
                console.log("Couldn't read " + setting.NPS_loadFile, red(err));
            }
            else {
                db.connect();
                db.query(sql,function(e,r){
                    if(e == null){
                        console.log(cyan('Database structure upgraded.'));
                    }else{
                        sendError(ws,"<h1>SQL Error during upgrade</h1>"+e,e);
                    }
                });
            }
        });
    }else{
        console.log("Couldn't read " + setting.NPS_loadFile, red(err));
    }
});

【问题讨论】:

  • 对我来说很好用。你遇到了什么错误?
  • Andrey,你是通过node-mysql执行的吗?
  • 是的。尝试了 node-mysql 和 node-mysql2

标签: mysql node.js node-mysql


【解决方案1】:

已解决。我们在正在执行的文件中犯了一个错误。抱歉耽误您的时间。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-01
    • 2014-01-10
    • 2013-03-25
    • 1970-01-01
    • 1970-01-01
    • 2012-06-21
    • 1970-01-01
    • 2016-07-10
    相关资源
    最近更新 更多