mysql loader error? 'C:test.txt' not found (Errcode: 2) - mysql

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

Related

Importing CSV file to HeidiSQL, error 1148

I'm completely novice to MySQL, and I'm trying to load some CSV sheets to the server using HeidiSQL -> tools -> Import CSV. But it keeps giving me this error:
Error 1148: The used command is not allowed with this MySQL version".
Is there a way to fix that, or maybe another way to load a CSV?
For query based csv import you can use load data ... to load csv files.
For more info refer here
Example:
To skip the first line which is header in csv you can use ignore 1 lines
load data local infile 'D:std_table.csv' into table local.student
fields terminated by ','
enclosed by '"'
lines terminated by '\r\n'
ignore 1 lines;
For windows based system use \r\n for line termination and for Linux use \n
Side Note:
You could try using MySQL Workbench for MySQL from official site here.
try this one:
LOAD DATA INFILE 'c:/tmp/discounts.csv'
INTO TABLE discounts
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;

import csv file into mysql using LOAD DATA INFILE

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

How do I export csv file to my computer in mysql

I am trying to export a table from a remote server to my desktop computer in csv format. I have this code:
select * from order
into outfile 'C:\Users\Sleep Shop\Desktop\MySQL Scripts/outfile.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n';
but I get this error:
failed : Can't create/write to file '/var/lib/mysql/C:\Users\Sleep Shop\Desktop\MySQL Scripts/outfile.csv' (Errcode: 2)
I'm thinking there is something fundamental I don't understand about this procedure, probably something to do the table being at a remote server. Can anyone help?
I used this code to tell a spot on the server to create the file:
select * from orders
into outfile '/var/www/test/outfile.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n';
It creates the file but it contains no records and I get this error:
failed : Field separator argument is not what is expected;
Change the query like this:
select * from `order`
into outfile 'export.csv'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\r\n';
Then you will find the file in your remote server's directory here: /var/lib/mysql/export.csv (or possibly /var/lib/mysql/data/your-db-name/export.csv)
Connect to your server via SSH (use putty) and transfer the file to your PC or move the file to a directory that accepts FTP access and you can download it using an FTP client (ie. filezilla, winSCP).
Or you can use phpMyAdmin and click on the table, then click the "export" tab, and then you will see an option to select "CSV" from the format dropdown. This may not work if your table is too large (depends on phpMyAdmin's settings or PHP's settings on how long a script can run).

How to import csv to mysql table?

Error: This query is just inserting the 1 line of file
LOAD DATA INFILE 'file.csv' INTO TABLE coords FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
And the file has 300k lines.
Columns are separeted by commas.
How is the coords created? Does it have 10 attributes for the data?
I just ran a quick test with a file containing six identical lines (using your data) and entered:
LOAD DATA LOCAL INFILE 'file.csv' INTO TABLE coord FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n';
It read all 6 lines in.
I did this under Linux. If you're on Windows maybe you need '\r\n' (?).

MYSQL LOAD DATA INFILE Syntax Error - where is it wrong?

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