Created
May 9, 2016 15:10
-
-
Save Olousouzian/504c4f57e2746cbd3def21e0df6cbdf2 to your computer and use it in GitHub Desktop.
Import CSV file with Mysql CLI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- This following script / snippets can be used for import CSV file directly into MySQL | |
-- Advantages : very very fast (15.000.000 lines --> ~5min) | |
-- First use mysql cli binary with local-infile flag | |
-- mysql --local-infile -uThisisusername -pGreatPassword database | |
-- Clear table if you need to | |
TRUNCATE TABLE big_tables_numbers; | |
-- Now the magics lines | |
set autocommit = 0; | |
set unique_checks = 0; | |
set foreign_key_checks = 0; | |
set sql_log_bin=0; | |
LOAD DATA LOCAL INFILE 'MY_BIG_FILE.csv' INTO TABLE big_tables_numbers | |
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (ID,FIRST_COL,S_COL,OTHER_COL,AGAIN,MORE,INFINITE,NO_END,HELL,PARADISE,WHY_NOT); | |
commit; | |
set autocommit = 1; | |
set unique_checks = 1; | |
set foreign_key_checks = 1; | |
set sql_log_bin=1; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment