1

Below is the Mysql command which i used to write the specific table columns into a file called result.txt

Select EMAILID,ZUID from MailBox INTO OUTFILE 'result.txt';

After executing the command i get the output

Query OK, 8 rows affected (0.00 sec)

But when i search for the file , i find that it hasn't been created. So please clarify whether this command actually writes the command into the file?? If not, what is the correct command to write sql command's result into an output file??. Sorry in case the question sounds noobish.

3
  • 1
    generally it goes into the system temp directory. e.g. /tmp/result.txt. perhaps it'd be c:\windows\temp\result.txt or c:\users\yourusername\appdata\local\temp, etc... many options Commented Nov 28, 2013 at 20:02
  • @Marc: Thanks..am using linux and am able to create the file in the /tmp/ directory but not able to create under home directory!! Commented Nov 28, 2013 at 20:37
  • remember that the mysql server is the one creating the file, and it will not have access rights to your home directory. Commented Nov 28, 2013 at 20:38

1 Answer 1

3

As the documentation states, it does output the results to a file. You are most likely not looking for the file in the right place. Try adding an absolute path instead of a relative one.

You should also take into account that the owner of the file is the mysql user (at least in linux).

Sign up to request clarification or add additional context in comments.

6 Comments

ERROR 1 (HY000): I am running on ubuntu..Can't create/write to file '/etc/mysql/results.txt' (Errcode: 13).. this is the error i get when i specify the absolute path.
It is not a good idea to output query results into the system configuration :) Create a folder in your home, eg: /home/aarish/test/ then give it additional privs (eg: chmod 777 /home/aarish/test) and then output to the file /home/aarish/test/results.txt. That should work. Using /tmp is another option.
Creating the file in the /tmp folder works..Thank you:).. but while trying to write to a file ,by changing its directory's access permissions in the way u stated ,gives me the same error "ERROR 1 (HY000): Can't create/write to file '/home/aarish/test/results.txt' (Errcode: 13)":(
Remember these files are created as if the mysql user is doing it, so you must be able to access this as another user. Many Linux distributions wall-off home directories, so you'll have to chmod +rx ~aarish
Why is there a space in the middle of that?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.