0

I have read many postings and done numerous google searches with different key words to find the answer to this question. While there are many postings on the topic, none of the postings gives an answer that works on my machine, so I am creating a new posting.

I have MySQL 5.6 installed on a windows development machine that is not connected to a network. I am trying to export data from a table into an outfile which I can then use for other purposes. the query runs successfully. In fact, when I try to run the same query a second time, I get a message saying that the outfile already exists. But when I go hunting for the file by its name, or using windows explorer, I cannot find it.

WHERE IS THE OUTFILE IN WINDOWS 7, USING MYSQL 5.6?

Here is code to create the outfile:

SELECT * INTO OUTFILE 'table.csv'
    FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
    LINES TERMINATED BY '\n'
FROM table  
CodeMed
  • 9,527
  • 70
  • 212
  • 364
  • possible duplicate of http://stackoverflow.com/questions/11484471/cant-find-the-file-created-by-outfile-in-mysql – Riz Mar 26 '14 at 20:47
  • @Riz It is not a duplicate question, which you will understand if you read my posting above. – CodeMed Mar 26 '14 at 20:48

2 Answers2

2

Use the following syntax : - you tell him where to put it !

SELECT * INTO OUTFILE 'c:/table.csv'
    FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
    LINES TERMINATED BY '\n'
FROM table

It normally stored in the DATA_DIR parameter location.

Up_One
  • 5,213
  • 3
  • 33
  • 65
1

From the reference manual for the SELECT statement:

SELECT ... INTO OUTFILE is the complement of LOAD DATA INFILE.

From the reference manual for the LOAD DATA INFILE:

The server uses the following rules to locate the file:

  • If the file name is an absolute path name, the server uses it as given.
  • If the file name is a relative path name with one or more leading components, the server searches for the file relative to the server's data directory.
  • If a file name with no leading components is given, the server looks for the file in the database directory of the default database.

So I would look in the default database directory. To find out which it is:

show variables like 'datadir';

You can, of course, define the location of the file specifying in your select... into outfile... sentence.

Also, if you have the MySQL installed in your cliente (or you are working on localhost), you can write something like this in the command line:

mysql [connection parameters] -e"select ..." > yourFile.txt

This will dump the result of your select statement into yourFile.txt in the current directory.

Hope this helps

Community
  • 1
  • 1
Barranka
  • 20,547
  • 13
  • 65
  • 83
  • +1 and thank you. Someone else answered faster with something that is targeted at the specific thing that was causing the problem on my machine. – CodeMed Mar 26 '14 at 20:52