DB(Database)/MySQL

[MySQL] ๋Œ€์šฉ๋Ÿ‰ ํ…Œ์ด๋ธ” csv, txt ํŒŒ์ผ ํ˜•ํƒœ๋กœ ๋‚ด๋ณด๋‚ด๊ธฐ & ๋ถˆ๋Ÿฌ์˜ค๊ธฐ

ํƒฑ์ ค 2021. 2. 9. 11:29

txt ํŒŒ์ผ๋กœ ๋‚ด๋ณด๋‚ด๊ธฐ

select *
	from [ํ…Œ์ด๋ธ”๋ช…]
    into outfile '[ํŒŒ์ผ๋ช…].txt' character set utf8mb4
    fields terminated by ',', optionally enclosed by '"'
    escaped by '\\'
    lines terminated by '\n';

csv ํŒŒ์ผ๋กœ ๋‚ด๋ณด๋‚ด๊ธฐ

select *
	from [ํ…Œ์ด๋ธ”๋ช…]
    into outfile '[ํŒŒ์ผ๋ช…].csv' character set utf8mb4
    fields terminated by ',', optionally enclosed by '"'
    escaped by '\\'
    lines terminated by '\n';

txt ํŒŒ์ผ ํ…Œ์ด๋ธ”๋กœ ์ฝ์–ด์˜ค๊ธฐ

load data infile '[ํŒŒ์ผ๋ช…].txt'
	into table [ํ…Œ์ด๋ธ”๋ช…] character set utf8mb4
fields terminated by ','
enclosed by '"'
lines terminated by '\n';
-- ignore 1 rows; -- ์—ด ์ด๋ฆ„ ๋ฌด์‹œํ•˜๊ณ  ํ…Œ์ด๋ธ”์— ํ–‰ ์ €์žฅํ•˜๊ธฐ (์ฒซ ์ค„ ๋ฌด์‹œ)

csv ํŒŒ์ผ ํ…Œ์ด๋ธ”์— ์ฝ์–ด์˜ค๊ธฐ

load data infile '[ํŒŒ์ผ๋ช…].csv'
	into table [ํ…Œ์ด๋ธ”๋ช…] character set utf8mb4
fields terminated by ','
enclosed by '"'
lines terminated by '\n'
ignore 1 rows; -- ์—ด ์ด๋ฆ„ ๋ฌด์‹œํ•˜๊ณ  ํ…Œ์ด๋ธ”์— ํ–‰ ๊ฐ€์ ธ์˜ค๊ธฐ (์ฒซ ์ค„ ๋ฌด์‹œ)
728x90