Import of csv file into mysql(Linux)
LOAD DATA
INFILE '/path to csv file/' INTO TABLE 'tbl_name'
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(@col1,@col2) SET fileld1=@col1,field2=@col2;
Import of csv file into mysql(Windows)
LOAD DATA
LOCAL INFILE '//path to csv file//'
INTO TABLE `tbl_name`
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES
TERMINATED BY '\r\n'
(`field1, `field2`,
`field3`, `field4`)
Export of mysql data into csv file(Linux)
SELECT col1,col2
union
SELECT
col1,col2 INTO OUTFILE
'/path to csv/'
from 'tbl_name'
FIELDS TERMINATED BY ','ENCLOSED BY '"'
LINES
TERMINATED BY '\n'
Export of mysql data into csv file(Windows)
SELECT col1,col2
union
SELECT col1,col2 INTO OUTFILE '\\path to csv\\'
FROM tbl_name
FIELDS
TERMINATED BY ','
ENCLOSED BY
'"'
LINES
TERMINATED BY '\n';
Find columns names from a table in case of large columns
(helpful while importing large data with column name)
select
GROUP_CONCAT(CONCAT("'",COLUMN_NAME,"'"))
from
INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'tbl_name'
AND
TABLE_SCHEMA = 'db_name'
order BY
ORDINAL_POSITION
0 comments:
Post a Comment