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';
Related
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.
When I try to run this command
select name, address, age into outfile 'user.csv' FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n' from StudentTable;"
I got an error from MySql:
"ERROR 1290 (HY000): The MySQL server is running with the
--secure-file-priv option so it cannot execute this statement"
Use
SELECT ##secure_file_priv;
To see what Folder is secure.
If it returns f.e
C:\ProgramData\MySQL\MySQL Server 8.0\Uploads\
Use
select name, address, age into outfile 'C:\\ProgramData\\MySQL\\MySQL Server 8.0\\Uploads\\user.csv'
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
from StudentTable;
the Backslashes must be doubled
To disable change in he my.ini file
[mysqld]
secure-file-priv = ""
But that is insecure, because you can save anywhere you have write rights, bit alsoo there mus specify the folder where you want to write it for example
c:\\temp\\user.csv
I am unable to load the data from file to a MySQL table.
Where else should I keep the file?
File is present as shown below.
notroot#ubuntu:~/lab/data$ ls
txns
notroot#ubuntu:~/lab/data$ pwd
/home/notroot/lab/data
notroot#ubuntu:~/lab/data$ mysql -u root -p
mysql> load data infile '/home/notroot/lab/data/txns' into table trans fields terminated by ',' lines terminated by '\n';
ERROR 29 (HY000): File '/home/notroot/lab/data/txns' not found (Errcode: 13)
mysql> load data local infile '/home/notroot/lab/data/txns' into table trans fields terminated by ',' lines terminated by '\n';
ERROR 1148 (42000): The used command is not allowed with this MySQL version
mysql>
Use the --local-infile parameter when running mysql
mysql --local-infile -u root -p
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
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?