Import CSV into MySQL (MariaDB)
Published on 16 Nov 2022
To load data from a CSV file you can just execute the following SQL command:
LOAD DATA INFILE "/home/fer/data.csv"
INTO TABLE __TABLE__
COLUMNS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES;
Additionally, you can add IGNORE statement after filename to ignore errors in rows:
LOAD DATA INFILE "/home/fer/data.csv" IGNORE
...
In the case you are running MySQL server with --secure-file-priv
option, you will get an error. To check it, you can execute the following query:
SHOW VARIABLES LIKE "secure_file_priv";
Then you have to move your csv file into the directory shown in secure-file-priv
, otherwise, you have to restart MySQL with secure-file-priv
disabled.
all tags
IDE architecture" cli crontab crypto csv database docker editor error exceptions fastapi ffmpeg filename git go history http iteration javascript linux logging me mysql numpy orm pdo pentaho php postgres python random rename rsync rust selenium server solana sql sqlite ssh typescript user w3m wordpress