MySQL OUTFILE query says "file already exists" but file does not exist at all

I am writing a very simple shell script to upload a table to a CSV file. Here is a part of it:

day=`/bin/date +'%Y-%m-%d'`
file="/tmp/table-$day.csv"
rm $file
query="SELECT * FROM table INTO OUTFILE '$file' FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\\n'"
echo "$query" | mysql <connection_parameters>

I insert rm $fileto make sure the file does not exist before the request is executed.

However, when I execute the script, I get conflicting messages:

rm: cannot remove `/tmp/table-2013-02-08.csv': No such file or directory
ERROR 1086 (HY000) at line 1: File '/tmp/table-2013-02-08.csv' already exists

I can not find OUTFILE anywhere in the machine.

So what's wrong ..?

Thank.

+5
source share
2 answers

I have found the answer.

OUTFILE creates the file on the MySQL server, and not on my MySQL client machine.

+8
source

Check if you have this in the / etc / passwd file

mysql: x: 27: 27: MariaDB Server: / var / lib / mysql: / sbin / nologin

change shell to / bin / bash instead

0

All Articles