无法使用 engine.ImportFile 导入长 SQL 文件 #1876

Closed
opened 2021-03-19 09:09:17 +00:00 by marcosteam · 2 comments

数据库是 Percona Server,该 SQL 文件一共 279 行,使用 engine.ImportFile 直接导入时大约会在 113 行出错,报错部分的提示为:

Error 1064: 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 'CREATE TABLE IF NOT EXISTS announcement ( id int(11) NOT NULL AUTO_INCREME' at line 13

这段附近的 SQL 源代码如下:

CREATE TABLE IF NOT EXISTS `invite_code` (
`id` int(11) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`),
`code` varchar(128) NOT NULL,
KEY `user_id` (`user_id`),
`user_id` int(11) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`updated_at` timestamp NOT NULL DEFAULT '2016-06-01 00:00:00'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

CREATE TABLE IF NOT EXISTS `announcement` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 PRIMARY KEY (`id`),
 `date` datetime NOT NULL,
 `content` LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
 `markdown` LONGTEXT NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

单独在 SQL 控制台中导入,测试通过。
将问题 SQL 单独抽出为文件,使用 engine.ImportFile 进行导入,测试通过。
使用 engine.Import 通过 bufio 导入,测试通过。

数据库是 Percona Server,该 SQL 文件一共 279 行,使用 engine.ImportFile 直接导入时大约会在 113 行出错,报错部分的提示为: Error 1064: 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 'CREATE TABLE IF NOT EXISTS `announcement` ( `id` int(11) NOT NULL AUTO_INCREME' at line 13 这段附近的 SQL 源代码如下: ``` CREATE TABLE IF NOT EXISTS `invite_code` ( `id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`), `code` varchar(128) NOT NULL, KEY `user_id` (`user_id`), `user_id` int(11) NOT NULL, `created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `updated_at` timestamp NOT NULL DEFAULT '2016-06-01 00:00:00' ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; CREATE TABLE IF NOT EXISTS `announcement` ( `id` int(11) NOT NULL AUTO_INCREMENT, PRIMARY KEY (`id`), `date` datetime NOT NULL, `content` LONGTEXT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, `markdown` LONGTEXT NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; ``` 单独在 SQL 控制台中导入,测试通过。 将问题 SQL 单独抽出为文件,使用 engine.ImportFile 进行导入,测试通过。 使用 engine.Import 通过 bufio 导入,测试通过。
marcosteam changed title from SQL 文件导入失败 to 无法使用 engine.ImportFile 导入长 SQL 文件 2021-03-19 09:55:30 +00:00
Owner

Which line is 279?

Which line is 279?
Author

Which line is 279?

当事 SQL 文件已经上传。

> Which line is 279? [当事 SQL 文件](https://gist.github.com/marcosteam/5f89c0486eb7f73522fe740741256157)已经上传。
lunny added the
kind
bug
label 2021-03-23 13:27:56 +00:00
lunny added this to the 1.1.1 milestone 2021-03-23 13:28:00 +00:00
lunny closed this issue 2021-03-23 13:34:43 +00:00
lunny modified the milestone from 1.1.1 to 1.1.0 2021-05-14 09:05:51 +00:00
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: xorm/xorm#1876
No description provided.