where is the Synthax error here?
LOAD DATA INFILE 'mysqlout_back.txt'
INTO TABLE temp (user,category,site,tld,ip,updated,date)
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n' ;
If you only want to load the data in specific columns, the go to the end:
LOAD DATA INFILE 'mysqlout_back.txt'
INTO TABLE temp FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\n'
(user,category,site,tld,ip,updated,date) ;
EDIT, regarding the file location in your comments:
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.
See the MySQL ref
Related
I am trying to run the following script
# Truncate is used to remove all records if already the table exists
TRUNCATE records;
#Change the path to your file location
LOAD DATA LOCAL INFILE 'C:\Users\amanda.ramos\Desktop\EdX_Enrollment.csv'
INTO TABLE records
# Each column in a CSV file is separated by ','
FIELDS TERMINATED BY ','
# Each line in a CSV file is separated by '\n'
#LINES TERMINATED BY '\n'
LINES TERMINATED BY '\r\n'
# Because we want to ignore the header of the .csv file. If your .csv does not have a header remove this line
IGNORE 1 LINES;
but I am getting an error message saying: 'error code: load data local infile file requested rejected due to restrictions on access. I tried running the following SHOW GLOBAL VARIABLES LIKE 'local_infile'; and it shows local_infile ON. Not sure why it doesn't work.
LOAD DATA INFILE 'returns_inprogress_06-Feb-2016-11-35.csv'
IGNORE INTO TABLE fkreturn
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '"'
LINES TERMINATED BY '\n'
(`FSN`,`Product`,`Order Id`,`ORDER ITEM ID`,`SKU Code`,`Return ID`,`Return Created On`,`Return Action`,`Return Type`,`Is FA`,`New Order Item Id`,`Sub Reason`,`Comments`,`Shipment Status`,`Tracking Id`,`Good Quantity`,`Bad Quantity`,`Total Price`,`Quantity`);
when executed it gives a error "#1290 - The MySQL server is running with the --secure-file-priv option" so it cannot execute this statement. I am using windows wamp, CSV file is in www folder. All I want is to ignore the duplicates of primary key (Return ID) and upload others.Should this field be marked as unique also. Or any other easy way to upload csv to table ignoring duplicates
I am trying to upload a large .csv file into a database (not on a server, just on my local computer only for my use) on MySQL. I have been having the Error Code: 1290. The MySQL server is running with the --secure-file-priv option so it cannot execute this statement error thrown.
I put my .csv file into the specified 'safe' folder (C:/ProgramData/MySQL/MySQL Server 5.7/Uploads) specified in the 'my' file, but it kept giving me the same error. Every solution I've seen has been using that folder destination and since that doesn't work can anyone help me get around or turn off the secure-file-priv option?
Here is my code in case wanted:
LOAD DATA INFILE 'C:\ProgramData\MySQL\MySQL Server 5.7\Uploads\my-file.csv'
INTO TABLE my-table
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
Thank you for any help
From the MySQL documentation for LOAD DATA INFILE:
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.
LOAD DATA INFILE "C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/my-file.csv"
INTO TABLE my-table
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
I had the same issue. Using forward slashes instead of backslashes (even on Windows machine) fixed it for me.
When I run the following code I get an error stating that the file is not found. I am not sure why. I checked the file names and they match.
load data local infile '/Users/blah/Desktop/A.csv'
into table B fields terminated by ','
enclosed by '"' lines terminated by '\n' ;
For security, MySQL only knows about it's directory structure. If it were able to read /Users/... then that would be a security gap.
To resolve, you can copy the A.csv into /var/lib/mysql/[Schema Name]/ and then "load data" that file.
Remember that the file path must be relative to the database server.
I tried the following code to load data from text document (file name is test.txt) to MySQL database, but it shows an error:
File 'C:test.txt' not found (Errcode: 2)
The query is:
LOAD DATA LOCAL INFILE 'C:test.txt' INTO TABLE messagebox fields terminated by ',' LINES TERMINATED BY '\n';
modify your drive address to C:\\test.txt
LOAD DATA LOCAL INFILE 'C:\\test.txt'
INTO TABLE 'messagebox'
fields terminated by ',' fields escaped by '\\' LINES TERMINATED BY '\n';
#Skyrel answer is perfect.In addition to that for Ubuntu users, use this command
LOAD DATA LOCAL INFILE '/home/user/test.txt'
You need a slash in your url
c:\test.txt