将 .xslx/.csv 文件导入 MySQL 数据库时出错

将 .xslx/.csv 文件导入 MySQL 数据库时出错

我有一个简单的 .xlsx 文件,我手动填写了它,它看起来像这样: 在此处输入图片描述

当我在 TextEdit 中打开此文件时,没有任何内容显示,并且(因此)此文件无法导入到 MySQLServer PhpMyAdmin

我将同一个文件保存为 .csv 。当我在 TextEdit 中打开此文件时,我得到以下结果:

id, questions, keywords, answer

1,here1,here2,here3

因此,.csv 不能直接导入到 MySQLServer 中,PhpMyAdmin但我收到以下错误:

Error
Static analysis:

5 errors were found during analysis.

A symbol name was expected! A reserved keyword can not be used as a column name without backquotes. (near "int" at position 46)
At least one column definition was expected. (near "int" at position 46)
Unexpected beginning of statement. (near "1" at position 50)
Unexpected beginning of statement. (near "`question`" at position 54)
Unrecognized statement type. (near "varchar" at position 65)
SQL query:

CREATE TABLE IF NOT EXISTS `Sample`.`TABLE 3` ( int(1), `question` varchar(5), `keywords` varchar(5), `answer` varchar(5)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

MySQL said: Documentation

#1064 - 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 'int(1), `question` varchar(5), `keywords` varchar(5), `answer` varchar(5)) DEFAU' at line 1

如果我简单地在 Textedit 的 .csv 文件中添加双引号,方法如下:

id, questions, keywords, answer

"1","here1","here2","here3"

然后表就正确导入到数据库了。

为什么我不能简单地在我的 excel 文件中写下一些内容,将其保存为 .xlsx 或 .csv,然后直接在 TextEdit 中获得正确的格式,以便可以在 MySQLServer 中成功导入?

当我尝试在数据库中导入表时,带有选项的窗口如下所示:

在此处输入图片描述

我已经将许多这样的 .odt 文件(Libre Office)导入数据库,但似乎 Libre Office 会自动处理这些事情,而 Excel 却没有。

相关内容