Error 1064: You have an error in your SQL syntax when importing schema exported by dumpling using lightning

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: dumpling导出schema后用lightning导入时发生Error 1064: You have an error in your SQL syntax

| username: Qiuchi

[TiDB Usage Environment] Test
[TiDB Version] v6.5.0

When using dumpling to export the schema and then importing it with lightning, an Error 1064 occurs: You have an error in your SQL syntax, but there is no error in the DDL itself.

nohup tiup dumpling -u ?-p ? -P 4000 -h 127.0.0.1 -d -o $dump_dir --filter 'dcdb.*' > $dump_dir/dumpling-out.log &

[mydumper.csv]
separator = ‘~@’
delimiter = ‘"’
header = true
not-null = false
null = ‘\N’
backslash-escape = true

nohup tiup tidb-lightning -config tidb-lightning.toml -d ? 2>&1 &

Lightning prompt:

[2024/02/22 14:03:06.672 +08:00] [WARN] [restore.go:537] ["failed to rewrite statement, will use raw input instead"]["run create schema job failed with no retry"]

[2024/02/22 14:03:07.067 +08:00] [ERROR] [restore.go:785] ["restore all schema failed"] [takeTime=437.05098ms] [error="[Lightning:Restore:ErrCreateSchema]create schema failed, table: `dcdb_1`.`MR_TZ_FUNDACCTLINK`, stmt: restore table schema: run create schema job failed: Error 1064: You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 33 near \"\"MR_TZ_FUNDACCTLINK\" (\n\"PROJECTID\" int(11) NOT NULL DEFAULT '0',\n\"FUNDACCTTYPE\" char(1) NOT NULL DEFAULT ' ',\n\"FUNDACCT\" varchar(32) NOT NULL,\n\"DEFAULTFLAG\" char(1) NOT NULL DEFAULT ' ',\nPRIMARY KEY (\"PROJECTID\",\"FUNDACCT\") /*T![clustered_index] CLUSTERED */,\nUNIQUE KEY \"FUNDACCTLINK_UNIQUE_INDEX\" (\"PROJECTID\",\"FUNDACCTTYPE\")\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin;\" "]
| username: Jasper | Original post link

Is the export and import being done on the same version of the TiDB cluster?

| username: Qiuchi | Original post link

It’s the same cluster, exporting from one database to another.

| username: tidb菜鸟一只 | Original post link

Check if there are any special symbols before the keyword MR_TZ_FUNDACCTLINK in the text.

| username: Jasper | Original post link

Is it possible for you to execute the create table SQL separately?

| username: Qiuchi | Original post link

Without special characters, I now suspect that it might be an issue with \n and ". I see that the DDL exported in the documentation uses backticks `, but here it uses double quotes ". However, I’m not sure if this can be adjusted?

| username: Qiuchi | Original post link

Yes, it can be executed.

| username: 胡杨树旁 | Original post link

The official introduction of lightning importing CSV files says that the table structure needs to be created manually.

| username: tidb菜鸟一只 | Original post link

Are all your table names in uppercase? When creating the table, you specified “MR_TZ_FUNDACCTLINK”—double quotes, but your delimiter also uses ‘"’—double quotes, which is causing the issue, right?

| username: Qiuchi | Original post link

Delimiter should only be used in the data, but I didn’t export the data, only the schema. The table names are all in lowercase, but I didn’t specify the case sensitivity when exporting with Dumpling.

| username: Qiuchi | Original post link

I just tried using sed to replace all double quotes with backticks, and found that the import was successful. It seems to be due to this issue, but I don’t know how to adjust dumpling to use backticks during export?

| username: WalterWj | Original post link

The schema information backed up feels off… Could it be a bug…?
Your backup command doesn’t seem to have any issues :thinking:.

| username: WalterWj | Original post link

It looks different?

| username: Qiuchi | Original post link

Could this be caused by some cluster configuration… May I ask if the result when you run show create table is also backticks?

| username: WalterWj | Original post link

Yes, there’s not much configuration :thinking:.

| username: Qiuchi | Original post link

Numb :expressionless:

| username: Qiuchi | Original post link

Found the reason, it’s because ANSI_QUOTES was enabled in the cluster’s sql_mode.

| username: WalterWj | Original post link

Excellent :100:

| username: dba远航 | Original post link

Displayed as a syntax error.

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.