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 '|';
Related
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.
I am using Mac with mysql workbench 8.0.19
when i run this
LOAD DATA LOCAL INFILE '~/Users/raianazaman/Desktop/DataBase/Sample.txt' INTO TABLE employee
FIELDS TERMINATED BY ','
ENCLOSED BY ''
LINES TERMINATED BY '\n'
IGNORE 0 LINES;
i get this error:
Error Code: 3948. Loading local data is disabled; this must be enabled on both the client and server sides
I have run this:
SHOW GLOBAL VARIABLES LIKE 'local_infile';
and it shows: 'local_infile','ON'
I have run this: SHOW GLOBAL VARIABLES LIKE 'local_infile'; and it shows: 'local_infile','ON'
I think you can run mysql --local-infile=1 -u root -p and try to load file again. It works for me.
I cant seem to use community server(or workbench for that matter) to use the Load local data infile command for csv. it always says cant use this command its not allowed on this version.
Ps I tried setting the local_infile global variable as 1 in the client cmd prompt but it still gives the same issue.Also i cant seem to give the parameters directly at start since the client opens on its own.(I dont have simple mysql command on windows only community server)
Why you want to use load local data infile command in Workbench? It already provides the option for table data import wizard.
Also, for the particular error, I tried following code and it worked for me:
(Before connecting to MySQL database type following)
mysql -u username -p --local-infile databasename
Enter Password:
Now, try using the database and importing the table.
MySQL> use databasename;
MySQL> load data local infile 'filename/filelocation.csv' into table tablename
-> fields terminated by ','
-> enclosed by '\r\n'
-> ignore 1 lines
-> (col1, col2, col3...);
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.
I'm trying to add a few hundreds of registers in a MySQL table in an Amazon RDS instance and when I do:
LOAD DATA LOCAL INFILE '/home/user/file.csv'
INTO TABLE databasename.tablename
FIELDS TERMINATED BY ' ' LINES TERMINATED BY ',';
I get this error:
Error Code: 2. File '/home/user/file.csv' not found (Errcode: 2)
If I try using LOAD DATA INFILE instead of LOAD DATA LOCAL INFILE I get:
Error Code: 1045. Access denied for user 'user'#'%' (using password: YES)
I'm using MySQL Workbench but also tried from command line.
How can I upload a local CSV into that table?
Try to add flag --local-infile when connecting to mysql using command line mysql client.
the connection should have parameter local-infile=1(on), can be added in code or to advanced connection options in the Workbench