Export Large CSV file into Mysql database
-- To export large CSV file into MySQL database, first you need to create that table (empty).
-- Remove (comment) "strict_trans_tables" sql_mode from your mysql configuration (my.cnf in linux and my.ini in windows).
-- Run MySQL command line client from the start menu.
-- The console will open, provide MySQL password.
-- select your database
use <name_of_your_database>;
-- Execute below command:
LOAD DATA INFILE 'D:\\Data.csv' IGNORE INTO TABLE your_table_name fields terminated BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\r\n';
-- Remove (comment) "strict_trans_tables" sql_mode from your mysql configuration (my.cnf in linux and my.ini in windows).
-- Run MySQL command line client from the start menu.
-- The console will open, provide MySQL password.
-- select your database
use <name_of_your_database>;
-- Execute below command:
LOAD DATA INFILE 'D:\\Data.csv' IGNORE INTO TABLE your_table_name fields terminated BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\r\n';
-- IGNORE keyword in above statement will ignore the errors and rows in csv that have errors and export remaining rows in table.
-- If your csv don't have any errors and missing data then you can call the statement without IGNORE statement like:
LOAD DATA INFILE 'D:\\Data.csv' INTO TABLE your_table_table fields terminated BY ',' OPTIONALLY ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\r\n';
-- '\r\n' these options in LINES TERMINATED will be changed in Linux.
information link: https://arctype.com/blog/mysql-load-data-infile/
Comments
Post a Comment