Use the LOAD DATA query:
mysql> LOAD DATA INFILE 'data.txt' INTO TABLE db2.my_table;
To store a query to a CSV file:
mysql> select * from my_table INTO OUTFILE '/tmp/my_table' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
Note that mysql cannot write anywhere in the file system, just in /tmp/ for security reasons, so just move the file afterwards.