import txt files into mysql
테이블 콤마로 내보내기
mysql -uuser -ppassword dbname -e "select * into outfile '/home/username/www/tablename.txt' fields terminated by ',' from tablename"
이작업을 하기전에 테이블하고 필드가 존재해야함.
load data local infile '~/file.txt' into table tablename columns terminated by ',';
mysql 인코딩이 utf8인데도 한글이 깨지는 경우.
SET character_set_database=utf8;
load data local infile '~/file.txt' into table tablename columns terminated by ',';
SET character_set_database=default;
이건 뭐가 잘못된건지 에러만 나온다. --local 을 붙여도 동일.
mysqlimport -uuser -ppasswd --fields-terminated-by=, dbname table file.txt
mysqlimport: Error: 2, File '/root/table' not found (Errcode: 2), when using table: table
이것저것 바꿔가며 나오는 오류를 확인해보니 파일명을 테이블명으로 바꿔줘야 등록되는 것을 확인.
mysqlimport -uuser -ppasswd --fields-terminated-by=, dbname --local ~/tablename.txt
옵션을 찾아보면 있을텐데 못찾겠음.