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).
Related
I am trying to load a .csv file into my table named ImportMaia, and I have used the following code to do so:
LOAD DATA INFILE 'C:\Users\esomm\Documents\Maia.xlsx' INTO TABLE MaiaImport
FIELDS TERMINATED BY '\t';
I was given the following error:
"The MySQL server is running with --secure-file-priv option so it cannot execute this statement"
I tried to use SET GLOBAL local_infile=1;, but that didn't help. Any thoughts?
The command must be, to disable it
SET GLOBAL local_infile= "OFF";
But i doubt that it will tun even then, Look at the file in an hex editor and see if the codes match with https://en.wikipedia.org/wiki/Control_character
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!
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.
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.
I would like to include a user variable in the MySQL `LOAD DATA LOCAL INFILE' file path. Our small team often accesses raw data files from Dropbox, so everyone has to find/replace the user name in the path definitions.
I was expecting the following to work but keep getting syntax errors:
SET #USER := 'user';
SET sql_mode='PIPES_AS_CONCAT';
LOAD DATA LOCAL
INFILE '/Users/' || #USER || '/Dropbox/Data/data.csv'
Also fails with CONCAT(). Any ideas? Thanks!
Similar questions asked here: Load data Infile #variable into infile error but without accepted answer.
A citation from MySQL documentation:
The file name must be given as a literal string. On Windows, specify backslashes in path names as forward slashes or doubled backslashes. The character_set_filesystem system variable controls the interpretation of the file name.
That means that it can not be a parameter of a prepared statement, stored procedure, or anything "server-side". The string/path evaluation must be done client side.