问题
When I run
mysql> select * into outfile "/home/akihirom/file1.txt" from BAIT_INTERACTION;
I get the following error:
ERROR 1 (HY000): Can't create/write to file '/home/akihirom/file1.txt' (Errcode: 13)
This happens even as root, in mysql or on the system itself. Does anyone know why this may be happening? Thanks
回答1:
I merged both examples into one and came up with the following that I used for a capistrano task. I was able to invoke a shell and run this from the command line.
mysql -uUSERNAME --database=${DBNAME} --execute=" SELECT * FROM ${TBNAME} INTO OUTFILE '/tmp/dumps/DBNAME.out' "
I added spacing before double quotes so you could see syntax differences.
回答2:
I was able to do the same thing using mysql dump by dumping the contents of the select statement to a file:
mysql -u USERNAME --password=PASSWORD --database=DATABASE --execute='SELECT `FIELD`, `FIELD` FROM `TABLE` LIMIT 0, 10000 ' -X > file.xml
Where I got the idea from
回答3:
Respect to ERROR 1 (HY000): Can't create/write to file '/home/akihirom/file1.txt' (Errcode: 13)
use only ' file1.txt' because server only writes on /var/lib/mysql/DB (where DB is a directory named as the data base) and later if you are root, go to there and manage the file as your needs.
You can use file1.cvs too; it works the same as file1.txt
来源:https://stackoverflow.com/questions/7209158/select-into-outfile-not-working-even-for-root