Reputation:
I am writing a very simple shell script to dump a table into CSV file. Here is 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 put in rm $file
to make sure that the file does not exist prior to the query's execution.
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 cannot find the OUTFILE anywhere in the machine.
So what is wrong.. ?
Thank you.
Upvotes: 7
Views: 5446
Reputation: 1
Check if you have this in /etc/passwd
mysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin
change shell to /bin/bash instead
Upvotes: 0
Reputation:
I have found the answer.
OUTFILE creates the file on the MySQL server, rather than on my MySQL client's machine.
Upvotes: 9