Convert sql to csv

来自cslt Wiki
2018年2月3日 (六) 11:41Wangyang讨论 | 贡献的版本

(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)
跳转至: 导航搜索

1. create database and load sql to it.

a) create database <database_name>
b) use <database_name>
c) source <xxx.sql>

2. obtain the column names and save csv.

a) select group_concat(concat("'",column_name,"'")) from information_schema.columns where table_name = '<table_name>';
b) select <column_string>
   union all 
   select * from <table_name> into outfile '/var/lib/mysql-files/xxx.csv' 
   fields terminated by ',' 
   optionally enclosed by '"' escaped by '\\' 
   lines terminated by '\n';

3. replace \N with in csv.

a) sed -i 's/\\N//g' xxx.csv