I created a simple .csv file with Excel which looks like this:
I also created the same .csv file by using Libre Office.
Both .csv files are looking absolutely the same at TextEdit:
id, questions
1, Hello World
However, when I try to import them to the MySQL database at PhpMyAdmin then some something surprising is happening. The latter file is properly imported to the database. But when I try to import the former file to it then I get the following error:
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
If I understand it right, this error occurs because the name of the first column in the .csv file is id
which is a reserved word for the database. Nevertheless, this error does not occur at all in the case of the .csv file which is created in Libre Office.
Why is this happening?