![将 .xslx/.csv 文件导入 MySQL 数据库时出错](https://linux22.com/image/1558927/%E5%B0%86%20.xslx%2F.csv%20%E6%96%87%E4%BB%B6%E5%AF%BC%E5%85%A5%20MySQL%20%E6%95%B0%E6%8D%AE%E5%BA%93%E6%97%B6%E5%87%BA%E9%94%99.png)
我有一个简单的 .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 却没有。