• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1644
  • Last Modified:

LOAD DATA LOCAL INFILE Vs Backslash

Hi

I'm using LOAD DATA LOCAL INFILE to import a comma separated file. However the file contains \(backslashes). Are there any way to get mysql not to escape thoses
0
sduItService
Asked:
sduItService
  • 3
  • 3
1 Solution
 
todd_farmerCommented:
Hi sduItService,

LOAD DATA INFILE ... FIELDS ESCAPED BY '';  

Cheers!
0
 
sduItServiceAuthor Commented:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use near 'FIELD
S ESCAPED BY ''
0
 
todd_farmerCommented:
What are you using as the actual command?  You will need to replace the ... with your existing parameters.  If you want to give me the full SQL command you were using initially, I can alter it for you.  I just don't know the other elements (file name, etc.) you are using.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
sduItServiceAuthor Commented:
use pcounter;
drop table log;
CREATE TABLE log (Username VARCHAR(15), Filename VARCHAR(100), Printer VARCHAR(50), Dato VARCHAR(15),tid VARCHAR(15), Workstation VARCHAR(20), spacer1 VARCHAR(20), spacer2 VARCHAR(20), Papertype VARCHAR(15), Parameters VARCHAR(50), Size VARCHAR(10), Pages VARCHAR(10), Cost VARCHAR(10), Balance VARCHAR(10));
LOAD DATA LOCAL INFILE 'C:\\temp\\pcounter.log'
INTO TABLE log
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
FIELDS ESCAPED BY ''
(Username, Filename, Printer, Dato, tid, Workstation, spacer1, spacer2, Papertype, Parameters, Size, Pages, Cost, Balance);
0
 
todd_farmerCommented:
Try this:

LOAD DATA LOCAL INFILE 'C:\\temp\\pcounter.log'
INTO TABLE log
FIELDS TERMINATED BY ','
ESCAPED BY ''
LINES TERMINATED BY '\n'
(Username, Filename, Printer, Dato, tid, Workstation, spacer1, spacer2, Papertype, Parameters, Size, Pages, Cost, Balance);

Also note that you don't have to drop and recreate the table unless you are changing the table format - you can replace the DROP and CREATE statements with the following:

TRUNCATE log;

0
 
sduItServiceAuthor Commented:
thx mate. It did the the job.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now