使用node.js在MySQL中创建表时出错

时间:2018-12-08 15:00:04

标签: mysql node.js parse-error

我在MySQL中创建表时遇到问题,该表返回ER_Parse_Error。我一直在浏览表格,找不到导致错误的原因,如果有人可以看看,我将不胜感激。 下表是: Table.

这是它返回的错误: Error returned.

编辑:这是文本表格:

//Cian
var mysql = require('mysql');
var con = mysql.createConnection({
 host: "localhost",
 user: "root",
 password: "",
 database: "******"
});
con.connect(function(err) {
 if (err) throw err;
 console.log("Connected!");
var sql = "CREATE TABLE Order ( order_id INTEGER(10) AUTO_INCREMENT PRIMARY KEY, order_description VARCHAR(255),order_date DATETIME,order_state VARCHAR(255),order_report_id integer(10))";
 con.query(sql, function (err, result) {
 if (err) throw err;
 console.log("Table created");
 });
});

这是文本中的错误:

Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'Order ( order_id INTEGER(10) AUTO_INCREMENT PRIMARY KEY, order_description VARCH' at line 1
    at Query.Sequence._packetToError (H:\node_modules\mysql\lib\protocol\sequences\Sequence.js:47:14)
    at Query.ErrorPacket (H:\node_modules\mysql\lib\protocol\sequences\Query.js:77:18)
    at Protocol._parsePacket (H:\node_modules\mysql\lib\protocol\Protocol.js:278:23)
    at Parser.write (H:\node_modules\mysql\lib\protocol\Parser.js:76:12)
    at Protocol.write (H:\node_modules\mysql\lib\protocol\Protocol.js:38:16)
    at Socket.<anonymous> (H:\node_modules\mysql\lib\Connection.js:91:28)
    at Socket.<anonymous> (H:\node_modules\mysql\lib\Connection.js:502:10)
    at Socket.emit (events.js:182:13)
    at addChunk (_stream_readable.js:283:12)
    at readableAddChunk (_stream_readable.js:264:11)
    --------------------
    at Protocol._enqueue (H:\node_modules\mysql\lib\protocol\Protocol.js:144:48)
    at Connection.query (H:\node_modules\mysql\lib\Connection.js:200:25)
    at Handshake.<anonymous> (H:\Cloud\create_tables.js:120:6)
    at Handshake.<anonymous> (H:\node_modules\mysql\lib\Connection.js:502:10)
    at Handshake._callback (H:\node_modules\mysql\lib\Connection.js:468:16)
    at Handshake.Sequence.end (H:\node_modules\mysql\lib\protocol\sequences\Sequence.js:83:24)
    at Handshake.Sequence.OkPacket (H:\node_modules\mysql\lib\protocol\sequences\Sequence.js:92:8)
    at Protocol._parsePacket (H:\node_modules\mysql\lib\protocol\Protocol.js:278:23)
    at Parser.write (H:\node_modules\mysql\lib\protocol\Parser.js:76:12)
    at Protocol.write (H:\node_modules\mysql\lib\protocol\Protocol.js:38:16)

1 个答案:

答案 0 :(得分:0)

由于MySQL对mysql保留关键字不区分大小写,因此 Order order 相同,而 order 是MySQL保留关键字,因此您无法通过订单名称创建类似的表格。

因此,如果您要使用此名称创建表,请使用以下内容:

CREATE TABLE test.Order (order_id INTEGER(10) AUTO_INCREMENT PRIMARY KEY,  order_description VARCHAR(255), order_date DATETIME, order_state VARCHAR(255), order_report_id integer(10));

这里的测试是我要在其中创建表的测试数据库。