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
Related
I've looked in previously asked questions and couldn't find the answer.
I created a table and want to load the data from a .CSV file using the following code:
LOAD DATA INFILE 'C:\...\*.csv'
INTO TABLE table_a
FIELDS TERMINATED BY ","
ENCLOSED BY '"'
LINES TERMINATED BY '/n'
IGNORE 1 ROWS;
but keep getting back this:
"Error Code: 1290. The MySQL server is running with the --secure-file-priv option so it cannot execute this statement"
Any suggestions?
PS - once I overcome this, could you please explain how to load .CSV data from an online URL instead of downloading the file first?
I'm running the "LOAD DATA FROM S3" command to load a CSV file from S3 to Aurora MySQL. The command works fine if run it in the Mysql Workbench (it gives me the below exception as warnings though but still inserts the dates fine), but when I run it in Java I get the following exception:
com.mysql.cj.jdbc.exceptions.MysqlDataTruncation:
Data truncation: Incorrect datetime value: '2018-05-16T00:31:14-07:00'
Is there a workaround? Is there something I need to setup on the mysql side or in my app to make this transformation seamless? Should I somehow run a REPLACE() command on the timestamp?
Update 1:
When I use REPLACE to remove the "-07:00" from the time original timestamp (2018-05-16T00:31:14-07:00) it loads the data appropriately. Here's my load statement:
LOAD DATA FROM S3 's3://bucket/object.csv'
REPLACE
INTO TABLE sample
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(#myDate)
SET `created-date` = replace(#myDate, '-07:00', ' ');
For obvious reasons it's not a good solution. Why would the LOAD statement work in the mysql workbench and not in my java code? Can I set some parameter to make it work? Any help is appreciated!!
The way I solved it is by using mysql's SUBSTRING function in the 'SET' part of the LOAD DATA query (instead of the 'replace'):
SUBSTRING(#myDate, 1, 10)
This way the trailing '-07:00' was removed (I actually opted to remove the time as well, since I didn't need it, but you can use it for TIMESTAMPS as well.
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).
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'm using this syntax to insert 50 records into a mySQL table from within a php script:
$sql = "LOAD DATA INFILE '/home/myusername/timeshts/hmo/tiertwo/myBuilders/BuilderTwo/sql-cron-files/overtime-item.sql' INTO TABLE `ot-item` CHARACTER SET 'utf8' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'";
$result = mysql_query($sql,$conn);
if($result) { echo "Load data Done!!!"; }
I'm mainly used to Windows paths and locations, this is Linux and i think its a path issue - i'm using an absolute server path since im not sure where the 'data directory or database directory is as advised in the mySQL documentation. I suppose i haven't got access to either of these directories on a shared host - so absolute is my best bet. Is there something i'm missing in the syntax that i just cant see?? I wrote the script so i know that lines are terminated by a new line character and columns are separated with a single commma char.
Just a guess, but maybe you are missing a / at the beginning of the path.
You need file privilege .
Contact your DBA to execute below command
grant file on . to 'usr'#'%';