use people;
SELECT 'first' UNION SELECT first from e where skills regexp "javapl" INTO OUTFILE '/home/ankit/csv/tablename.csv' 
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' 
LINES TERMINATED BY '\n';

this runs without problem to /var/tmp folder but other folders gave error:13 can't write please help

Recommended Answers

All 6 Replies

It is probably a permission issue

Privileges should be :
drwxrwxrwt
so anybody, including the "mysql" user, can use it. If is not like this you have to run this command from terminal:
chmod 0777 /home/ankit/csv

Hope this helps!

still that error occurs

Hello,

You ca try to edit /etc/apparmor.d/usr.sbin.mysqld (sudo gedit /etc/apparmor.d/usr.sbin.mysqld) and add /home/ankit/csv/ and /home/ankit/csv/* near the bottom like so:

...
/usr/sbin/mysqld {
    ...
    /var/log/mysql/ r,
    /var/log/mysql/* rw,
    /home/ankit/csv/ r,
    /home/ankit/csv/* rw,
}

And then reload AppArmor.

sudo /etc/init.d/apparmor reload

The question comes down to who owns the directory that you are trying to write the file into. In this case you want it to write the a directory under /home/ankit called csv which probably looks like this:

[root@hpsrvr ~]# ls -lad /home/ankit/csv
drwxr-xr-x 2 ankit ankit 4096 Nov 22  2012 /home/ankit/csv

Now that you know that simply add the mysql user to that group (stored in the /etc/group file) and set the directory permissions to 775. To add the mysql user to the ankit group use:

usermod -a -G ankit mysql
chmod 755 /home/ankit/csv

And it should now look like this:

[root@hpsrvr ~]# ls -lad /home/ankit/csv
drwxrwxr-x 2 ankit ankit 4096 Nov 22  2012 /home/ankit/csv

Let us know how it goes.

still the same error

SELECT 'first'

UNION SELECT first from e INTO OUTFILE '/home/ankit/csv/h.csv' 
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' 
LINES TERMINATED BY '\n';

it doesn't work

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.