node-mysql source命令如何使用?
发布于 1个月前 作者 zyoo 117 次浏览 来自 问答

求教,如题, node-mysql中直接使用source语句,直接报错,有没有办法解决?

1 回复

附上测试代码及相应错误信息

conn1.query('source test.sql', function(err, result) {
    if(err) {
        console.log(err.stack);
    }   
    else {
        console.log('exec source success');
    }   
});
> ~             

Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'source test.sql' at line 1
    at Query.Sequence._packetToError (/root/yanqiang/web/node_modules/mysql/lib/protocol/sequences/Sequence.js:48:14)
    at Query.ErrorPacket (/root/yanqiang/web/node_modules/mysql/lib/protocol/sequences/Query.js:82:18)
    at Protocol._parsePacket (/root/yanqiang/web/node_modules/mysql/lib/protocol/Protocol.js:270:23)
    at Parser.write (/root/yanqiang/web/node_modules/mysql/lib/protocol/Parser.js:77:12)
    at Protocol.write (/root/yanqiang/web/node_modules/mysql/lib/protocol/Protocol.js:39:16)
    at Socket.<anonymous> (/root/yanqiang/web/node_modules/mysql/lib/Connection.js:82:28)
    at Socket.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:748:14)
    at Socket.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:410:10)
    --------------------
    at Protocol._enqueue (/root/yanqiang/web/node_modules/mysql/lib/protocol/Protocol.js:135:48)
    at Connection.query (/root/yanqiang/web/node_modules/mysql/lib/Connection.js:184:25)
    at Object.<anonymous> (/root/yanqiang/web/test/test.js:33:7)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3
回到顶部