select * into outfile not working even for root

强颜欢笑 提交于 2019-12-11 05:40:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!