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

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.

Related

How import csv file into mysql /var/lib/mysql-files/

I need to import csv file into mysql:
first I tried:
LOAD DATA LOCAL INFILE 'C:/Users/MJ/Desktop/nysgi1.csv' INTO TABLE gift FIELDS TERMINATED BY ',' (giftid,date,udate,vamount);
errors:
ERROR 1148 (42000): The used command is not allowed with this MySQL version
And I then followed some instruction to successfully set local_infile ON ,and then I restarted mysql by using service mysql restart.However it not works,still the same error.
Then I tried to use directly:
LOAD DATA INFILE 'C:/Users/MJ/Desktop/nysgi1.csv' INTO TABLE gift FIELDS TERMINATED BY ',' (giftid,date,udate,vamount);
errors:
The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
So I use:
SELECT ##global.secure_file_priv;
and find out the directory is:
/var/lib/mysql-files/
My question is how to import the csv file to /var/lib/mysql-files/ using command line.
Thanks!
Seems you are having exactly the same problem i have,
please use scp command to place your csv file into linux directory.

mysql error (HY000):file not found (Errcode: 2)

So I'm trying to load my database by loading .txt file (fields terminated by \t). But it keeps sending me this error:
mysql> LOAD DATA LOCAL INFILE "C:\\tvshow.txt" INTO TABLE SERIJA FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n';
ERROR 2 (HY000): File 'C:\tvshow.txt' not found (Errcode: 2)
Can somebody help me out?
(I'm using PuTTY on Windows 10)

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.

INTO OUTFILE in SQL on MAC OSX - Errcode 13 "Permission denied"

I switched from being a long term windows user to mac.
Now I face this problem trying to save a query to a csv file:
mysql> SELECT * FROM mytable
-> INTO OUTFILE '/Users/localuser/Documents/myfolder/test.csv'
-> FIELDS TERMINATED BY ','
-> ENCLOSED BY '"'
-> LINES TERMINATED BY '\n';
But i get:
ERROR 1 (HY000): Can't create/write to file
'/Users/localuser/Documents/myfolder/test.csv' (Errcode: 13 "Permission denied")
I think it is something about setting permission but i have not found a solution that works for my mac osx.
thank you in advance.
Please take into account that this ones works
MySQL writing on a text file
But what I am looking for is more the operation to set any directory so that *.csv files can be put there by the sql server.
I meet the same problem, and I find that it is relevant to file permission of Mac OS, not relevant to MySQL.
The solution is to make all the folders in the path have permission of 755 (read and execution) and to make the folder putting the csv file has the permission of 777 which can write the file.
So in your case, the folders in '/Users/localuser/Documents' should have 755 permission and the folder 'myfolder' should have 777 permission.

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