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

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.

Related

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)

MariaDB load data infile permission error

I am attempting to load data into a MariaDB database. The ownership of the directory loaded from was modified as follows:
$ chown -R mysql load_data
permissions for the directory appear as:
drwxrwxr-x 2 mysql beta_user 4096 Jul 20 16:33 load_data
The data file, emp_list.dat, looks as follows:
Dineen,,Tim,Frog,1965-03-17
Blatter,,Greg,Butterfly,1975-10-18
Hank,Larry,Kevin,Aligator,1980-02-03
Jones,,Tom,Singer,1945-04-04
The load command in load_employees.sql is as follows:
load data infile
'/home/beta_user/sample_code/db/mariadb/load_data/emp_list.dat'
into table pktest.employees
fields terminated by ','
optionally enclosed by '"'
lines terminated by '\n'
(last_name,middle_name,first_name,pref_name,#dob)
set dob = str_to_date(#dob, '%y-%m-%d');
When I attempt to load data the following error appears:
$ mysql --defaults-file=~/bin/msqlpsw/msqlpkpsw.dat -D pktest -e "source /home/beta_user/sample_code/db/mariadb/load_data/load_employees.sql"
ERROR 13 (HY000) at line 1 in file: '/home/beta_user/sample_code/db/mariadb/load_data/load_employees.sql':
Can't get stat of '/home/beta_user/sample_code/db/mariadb/load_data/emp_list.dat'
(Errcode: 13 "Permission denied")
Can anybody suggest why the error given that the ownership of the directory is set to mysql ?

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.

MySQL LOAD DATA Error can't resolve...!

mysql> LOAD DATA INFILE '/abc.txt' INTO TABLE test1 FIELDS TERMINATED BY '|';
ERROR 13 (HY000): Can't get stat of '/abc.txt' (Errcode: 2)
I used LOAD DATA as per the syntax. But getting the above error. can anybody tell what is the error..!?
I tried searching google dev.mysql can't find what error it is??
Thanks in advance
If the file is on your MYSQL server try using the full path.
LOAD DATA INFILE '/var/tmp/abc.txt' INTO TABLE test1 FIELDS TERMINATED BY '|';
If the file isn't on the server and it is on your local machine, and your user has access to SCP files between the servers ( try this
scp abc.txt mysqlserver:
) then you should be able to do this (using full path again) ..
LOAD DATA LOCAL INFILE '/var/tmp/abc.txt' INTO TABLE test1 FIELDS TERMINATED BY '|';
If that doesn't work.. try renaming the file to test1.txt and using the 'mysqlimport' command?
Login to the mysql console using the following flag:
mysql -uroot -p --local-infile
and then enter the password.
After that execute the load data command as follows:
LOAD DATA LOCAL INFILE '/abc.txt' INTO TABLE test1 FIELDS TERMINATED BY '|';