MySQL: INTO OUTFILE csv in /home/* folder (Errcode:13) - mysql

I want to export an CSV into /home/test/log/a/logfile.csv.
Actually I am using
SELECT activity, timestamp FROM logging WHERE user = 'a' INTO OUTFILE '/home/test/log/a/logfile.csv' FIELDS TERMINATED BY ';' LINES TERMINATED BY '\n';
Now I get
Can't create/write to file '/home/test/log/a/logfile.csv' (Errcode: 13)
I already tried putting
/home/test/ r,
/home/test/** rwk,
AND
/home/test/log/a/ rwk,
into the /etc/apparmor.d/usr.sbin.mysqld and give /home/test/log/a rwx for others, but nothing worked. Any suggestions?

Related

MYSQL SELECT INTO OUTPUT FILE permission other than 640

I'm using Mysql 8.0.29 on Ubuntu 21.10.
That query works fine :
SELECT DISTINCT field1,field2
INTO OUTFILE '/tmp/output.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM mtable WHERE id < 20;
But the file created at permission 640 and I can't get it by ftp download.
I edit the /etc/init.d/mysql file and restarted the server :
UMASK=0640
export UMASK
UMASK_DIR=0750
export UMASK_DIR
But still permission 640 on the file.

MySQL export to file

I have a node js project with folder output. This folder has 777 permissions. I query SELECT INTO OUTFILE via node-mysql.
But I have Errcode: 13 - Permission denied error.
MySQL started with secure_file_priv=""
SQL:
SELECT * FROM users INTO OUTFILE '/home/ubuntu/Projects/output/1.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';

ERROR 13 (HY000): Can't get stat of '/tmp/file1.csv' (Errcode: 2) while trying to import CSV file into MariaDB

I am trying to import CSV file into MariaDB (version: 5.5.50-MariaDB MariaDB Server), using this command:
LOAD DATA INFILE 'file1.csv'
INTO TABLE table_name
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 LINES (#dummy,col1, col2,col3,#dummy)
SET col4 = "xyz";
I am getting error as:
ERROR 13 (HY000): Can't get stat of '/var/lib/mysql/db_name/file1.csv' (Errcode: 2)
I also tried using LOCAL keyword as per some suggestions on stackoverflow and google search in the above query like:
LOAD DATA LOCAL INFILE 'file1.csv'
INTO TABLE table_name
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 LINES (#dummy,col1, col2,col3,#dummy)
SET col4 = "xyz";
in that case, I get a file not found error:
ERROR 2 (HY000): File 'file1.csv' not found (Errcode: 2)
I have tried moving my source file to /tmp, /root and /var/lib/mysql/db_name directories but am not able to import using any of the above queries.
Could anyone please suggest a solution?
Thanks in advance.
The file needs to be either owned by "mysql", or readable by by "mysql". Do ls -l file1.csv if you need further interpretation.
Also, check the value of local_infile.

Exporting sql data from mysql server into csv file in local mac computer Help,

when I attempt to take the data I have from my mysql server and generate a csv file with this command:
select * from table into outfile '/Users/username/Desktop/testfile.csv' fields terminated by ',' enclosed by '"' lines terminated by '/n';
I end up with the error:
ERROR 1 (HY000): Can't create/write to file '/Users/username/Desktop/testfile.csv' (Errcode: 13 - Permission denied)
Another weird problem is I can't seem to stop the server from running through the preference pane, maybe they are related. Anyways, thanks for the help!
Try this:
SELECT * FROM table INTO OUTFILE '/tmp/myfile.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"';
Then in you terminal, cd to the tmp directory, do ls to see if the file is there and when you are in that tmp directory, just do open myfile.csv

Error when trying to export table to a csv file (errcode: 2)

I'm trying to export my table to a .csv file. The query (mysql) is:
SELECT *
FROM TEMP_FINAL
INTO OUTFILE '/home/test/TEMP_FINAL.csv'
FIELDS TERMINATED BY ';'
LINES TERMINATED BY '\n';
I get the following error:
"Can't create/write to file '/home/test/TEMP_FINAL.csv' (Errcode: 2)
The directory "test" has permission to write and I`m using Ubuntu 12.04.5 LTS.
What is wrong and how to fix it?
The mysql program does not have access to a user's directory. Change the outfile to somewhere like /tmp/ and move the file later.