MySQL: query result to file using console

Given a query like below to log the results to a text file


select id from accounts where deleted=1;

try using the command below to output the result to file to ‘C:\test.txt’


select id from accounts where deleted=1 into outfile 'C:\\test.txt';

try using the command below to output the reuslt to csv


select id from accounts where deleted=1 INTO OUTFILE 'C:\\test.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
MySQL: query result to file using console

Leave a comment