Mysql

無法調試這個簡單的 SQL 語句

  • May 31, 2017

我正在使用 LOAD DATA LOCAL INFILE 將數據導入 MySQL 表。我已經毫無困難地在另一個表上完成了此操作,我複制了 stmt 並只是更改了表名和欄位。這是聲明:

LOAD DATA LOCAL INFILE '/John/league_seasons.csv'
INTO TABLE lwl_league_players
IGNORE 1 LINES
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n'
(id, location_id, game_id, league_season_id, player_id);

這是錯誤:

MySQL 說:文件

#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 'FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n'
(id, location_id, game_id,' at line 4

FIELDS TERMINATED BY 和 LINES TERMINATED BY 行與我之前的工作語句完全相同。我檢查了結構,沒問題。

表結構

我很感激有人指出我搞砸了。謝謝

選項的順序很重要。

放置IGNORE 1 LINES後,接下來應該是列列表。

LOAD DATA LOCAL INFILE '/John/league_seasons.csv'
INTO TABLE lwl_league_players
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(id, location_id, game_id, league_season_id, player_id);

請參閱有關語法的 MySQL 文件,您將看到選項的正確順序。

引用自:https://dba.stackexchange.com/questions/175062