MySQL LOAD DATA Error (Errcode: 2 - "No such file or directory") - mysql

I am trying to load data into a table of my MySQL database, and getting this error.
LOAD DATA LOCAL INFILE 'C:\Users\Myself\Desktop\Blah Blah\LOAD DATA\week.txt'
INTO TABLE week;
Reference: this
The path is hundred percent correct, I copied it by pressing shift and clicking "copy path as" and checked it many times. So any tips on this will be much appreciated.
.
My research: Seeing this answer, I tried by changing C:\Users to C:\\Users. It did not work for me.
Secondly, is there a way to use some kind of a relative path (rather than an absolute path) here?

I spent 2 days on this and finally got my mistake, Just changing backslashes by forward ones, as one contributor previously said. And finally worked for me.
so was:
LOAD DATA LOCAL INFILE 'C:/ProgramData/MySQL/MySQL Server 5.7/Data/menagerie/pet.txt' INTO TABLE pet;
I just can say thanks a lot.
p.s. don't waste time on ytb...

I don't know what version of MySQL you are using but a quick Google search found possible answers to both your questions. Below are excerpts from the MySQL 5.1 Reference Manual:
The file name must be given as a literal string. On Windows, specify
backslashes in path names as forward slashes or doubled backslashes
The LOCAL keyword affects where the file is expected to be found:
If LOCAL is specified, the file is read by the client program on the
client host and sent to the server. The file can be given as a full
path name to specify its exact location. If given as a relative path
name, the name is interpreted relative to the directory in which the
client program was started.
Regards.

If using MySQL Workbench on a local Windows PC to connect to a remote MySQL server,
Add the "LOCAL" keyword
Add double backslashes "\\" to your folder path
If text file's first row has column names add "IGNORE 1 LINES".
LOAD DATA LOCAL INFILE 'C:\\MyTabDelimited.txt'
INTO TABLE my_table IGNORE 1 LINES;

Simply replace backslash with slash in the path.
This works for me (MySQL Workbench 6.3 on Win 10):
LOAD DATA LOCAL INFILE 'C:/Users/Myself/Desktop/Blah Blah/LOAD DATA/week.txt'
INTO TABLE week;
Ref. https://dev.mysql.com/doc/refman/5.5/en/loading-tables.html

One more reason for this type of error is another languge in the path.
You might have almost the entire path in English, but the username might be auto-filled in another language.

Try removing the word LOCAL from your query.

Try moving the week.txt file to the desktop
then execute in a terminal window:
LOAD DATA LOCAL INFILE 'C:\Users\Myself\Desktop\week.txt'
INTO TABLE week;

Instead of using double backslash That slash is also worked for me too.

I resolve this problem by replacing the path
Replace format "C:\Users\Myself\Desktop\week.txt"
With this different format "C:/Users/Myself/Desktop/week.txt"
My computer didnt recognize the ( \ ) symbols.

Related

I can't find my MySQL folder in %ProgramData%

First of all, I just want to say that I'm new to SQL, so forgive me if I'm being ignorant or something.
I'm working on this project and I need to import data from a text file. My first thought was to use this command:
LOAD DATA LOCAL INFILE '/tmp/test.txt' INTO TABLE names;
Where my text file is test and my table is names.
However, I got this error message:
Error Code: 2. File '\tmp\teste.txt' not found (Errcode: 2 - No such file or directory)
I tried to save this file in the tmp folder but I still got this same error. I was told that maybe the problem is in my.ini (something about the --secure-file-priv) but I just can't find my MySQL folder in C:\ProgramData. Apparently, that is where my.ini is supposed to be. So, any ideas of what is going on?
By the way, I'm not confusing C:\Program Files and C:\ProgramData
P.S: I use Windows 10 and MySQL Workbench 6.3 CE.
Alright pals, the problem is solved. I honestly don't know how I managed to find the problem but I did and as expected, it was a silly one. The correct statement would be:
load data infile 'c:\\wamp\\tmp\\test.txt' into table names;
I got confused with all that slashes thing, because for directories you use \ or /. So my mistake was doing this:
load data infile 'c:\wamp\tmp\test.txt' into table names;
Using only one backslash instead of two, which is wrong. Finally, I just needed to put my text file in the tmp folder and use the appropriate backslashes (no need for LOCAL). Thanks for the help!

MySQL : --secure-file-priv

I am learcing SQL and am trying to load a .csv file into it with "load infile" etc...
However I am getting the error, "The MySQL server is running with the --secure-file-priv so it cannot execute...".
I checked SHOW VARIABLES LIKE 'secure_file_priv' and it showed that the variable only allows loading data from C:\ProgramData\MySQL\MySQL Server 5.7\Uploads\
However after moving my data to that folder the same error keeps coming up. Can anybody help? Thanks. Andreas
I had the same problem when loading csv-files. As in https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_secure_file_priv described, you can only read and write in the path in the variable secure-file-priv.
Therefore you have to include the full path in the query. Since you did not post a concrete query, I can only guess that you tried something like LOAD DATA infile 'temp_0.csv' INTO TABLE series_data_in;. It should work with something like LOAD DATA infile '/var/lib/mysql-files/temp_0.csv' INTO TABLE series_data_in; (or in your case LOAD DATA infile 'C:/ProgramData/MySQL/MySQL\ Server\ 5.7/Uploads/temp_0.csv' INTO TABLE series_data_in ; - be aware of correctly escaped spaces).

global variable in MySQL

I dont think it is possible but there is no harm to ask.
I have this sql file :
LOAD DATA INFILE 'myfile.csv'
INTO TABLE TCONTACTN4DS
FIELDS TERMINATED BY ";"
LINES TERMINATED BY "\r\n"
if there is no path in the INFILE option, it goest to the data/name_of_the_DB folder to get the file.
I could put any path in the infile but let's assume that I dont know the path that will be used and I dont want those scripts to be changed.
Can I declare (dont know where exactly) a global variable that could be changed to describe the path ? How would I use it if it is possible ?
The mysql documentation on load data infile is very explicit about this, so no, you cannot do this:
The server uses the following rules to locate the file:
If the file name is an absolute path name, the server uses it as given.
If the file name is a relative path name with one or more leading components, the server searches for the file relative to the server's
data directory.
If a file name with no leading components is given, the server looks for the file in the database directory of the default database.
Since load data cannot be used in stored routines either, you cannot even have a workaround for this limitation.

load data local infile ERROR 2 file not found

I've been ramming my face against this sql error for about 45 minutes, and I have a feeling it's going to be something silly.
I'm trying to load a .txt file into my database, which is on a server elsewhere. I'm using putty on windows 7.
The sql call I am using is the following:
LOAD DATA LOCAL INFILE "C:/Users/Sam/Desktop/students_data.txt" INTO TABLE students;
The response I get is ERROR 2 (HYOOO): File 'C:/Users/Sam/Desktop/students_data.txt' not found (Errcode:2)
If anyone could shed some light on this that'd be extravagant. I already tried switching the / to \ and using single quotes, etc., but nothing seems to work. The file path is copied by shift+clicking the actual file and pasting it.
I have found a solution. First delete the word LOCAL from the sql statement. Second - place your file into MySQL DATA folder usually - bin/mysql/msql5.5.8/data/and your DB with which you are working. It worked for me. You might want to check your MAX_FILE upload number in php.ini file if file is large.
Removing the word LOCAL seemed to work for me; try it out!
Try to type path as C:\\mydir\\myfile.csv i.e. use \\ instead of \
I had this problem too, then I read this:
The file name must be given as a literal string. On Windows, specify
backslashes in path names as forward slashes or doubled backslashes
(from http://dev.mysql.com/doc/refman/5.1/en/load-data.html)
I did use the LOCAL keyword, but escaped the file path like this: str_replace('\\','/',$file), then it worked like a charm!
Had this too and solved it by using cmd.exe and found that the filename was mistakenly in the form filename.txt.txt and fixed it.
just replace "\" by "/" as the path directory before the filename.txt in (""). it will be better if u just keep the file in mysql data folder and do the thing i mentioned above.it will definitely work.
Sorry my previous answer is wrong.
In my case, I connect to a proxy, not the real physical mysql instance, so of course it could not get my local file.
To solve this, figure out the true physical mysql instance IP, connect it directly. You need help from the DBA.
LOAD DATA LOCAL INFILE 'C:\\cygwin\\home\\jml58z\\e_npv\\Fn_awk2010.mysql' INTO TABLE mydata
with the double \ it worked

Inserting a file into mysql DB via CMD

My question is simple I thought, but I did not get it right yet . .
I am having a simple db in mysql server 5.1 -
Which includes a file to be saved in as db format "blob"
How do I save a file in the database ? assuming it is 2 fields, one id - int one blob for the file !?! Is blob right ? Want to save microsoft word and pdf documents !!
I want to insert it via CMD, and struggel, when putting a file path in, it saves the path, but no file !!
E.G. >
INSERT INTO cvtable VALUES("1","???file path???");
Thank you guys for any hints here !!
Perhaps have a look at the LOAD DATA INFILE statement.
insert into cv (id,content) values ("1",LOAD_FILE('cv.doc'));
thats what i was looking for !!
finally !!!