Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL into outfile - where is the file stored? (MySQL, Windows)

I am using MySQL and would like the results of the following query to be stored in a csv file locally on my machine:

SELECT * INTO OUTFILE 'mysqlresults.csv' FIELDS TERMINATED BY ','OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM table;

I have searched for the file and it could not be located anywhere on the disk so it is not in the 'data' directory.

like image 413
tsotsi Avatar asked Jul 22 '15 09:07

tsotsi


1 Answers

Be default it stored in the MySQL's data directory. And you can check your data directory by command:

show variables like 'datadir';

You can't store it locally with this command running on remote server, you need to download the file from the server.

You can also use this command:

SELECT * FROM table INTO OUTFILE 'mysqlresults.csv' FIELDS TERMINATED BY ','OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' ;
like image 143
Aman Aggarwal Avatar answered Sep 21 '22 02:09

Aman Aggarwal