Mysql – MariaDB 10.2 – SQL Dump of specific columns

mariadbMySQL

I am aware of the --where condition while taking dump of table where we can give condition on rows. But I have a table of the size 15GB and have over 100 columns.I need a dump of few columns out of it, and I want to do this as scheduled job where I will take dump of few columns of the source DB and store it to another server for reporting purpose.I also tried INTO OUTFILE but It won't save output as .sql and as INSERT statement.

Best Answer

Create a view v_ip that contains only the columns you want, and then dump that view into a csv file.

select * from v_ip into outfile '/tmp/test.sql'
   fields terminated by ','
   enclosed by '"'
   lines terminated by '\n';

Importing should be done with "load data".