开发者

select * into outfile not working even for root

开发者 https://www.devze.com 2023-03-31 15:33 出处:网络
When I run mysql> select * into outfile \"/home/akihirom/file1.txt\" from BAIT_开发者_运维问答INTERACTION;

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


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.


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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号