LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-07-2008, 08:41 AM   #1
talat
Member
 
Registered: Jan 2006
Distribution: Centos
Posts: 145

Rep: Reputation: 16
Unhappy Mysql 'LOAD DATA INFILE' command error


Hi Guys,

Consider that i have extracted the data from table 'users' with the following command.

select localpart,username,clear INTO OUTFILE '/tmp/new_userdata1.txt' FIELDS TERMINATED BY ',' FROM users where username LIKE '%domain.net.pk';

Now when i try to load this data in the table 'users' with following command.

LOAD DATA INFILE '/tmp/new_userdata.txt' INTO TABLE users(localpart,username,clear) SET domain_id=19 FIELDS TERMINATED BY ',';

It gave me following error.


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 'FIELDS TERMINATED BY ','' at line 1


Can you plz tell me how to resolve it . I have run this command without 'FIELDS TERMINATED BY' clause and command successfully runs but did not put the desire record in the table. Plz help.

Regards
 
Old 01-07-2008, 10:46 AM   #2
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Try SET domain_id='19'.

From the manual:
Quote:
`LOAD DATA INFILE' regards all data as strings, so you cannot use
numeric values for `ENUM' or `SET' columns the way you can with
`INSERT' statements.
 
Old 01-07-2008, 10:58 AM   #3
talat
Member
 
Registered: Jan 2006
Distribution: Centos
Posts: 145

Original Poster
Rep: Reputation: 16
Hi

There was one mistake in my cmd i.e the SET clause comes at the end. But still after changing my cmd i am getting error.

LOAD DATA INFILE '/tmp/new_userdata1.txt' INTO TABLE users(localpart,username,clear) FIELDS TERMINATED BY ',' SET domain_id='19' ;


Following is the error.

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 'FIELDS TERMINATED BY ',' SET domain_id='19'' at line 1

Regards
 
Old 01-07-2008, 09:09 PM   #4
PTrenholme
Senior Member
 
Registered: Dec 2004
Location: Olympia, WA, USA
Distribution: Fedora, (K)Ubuntu
Posts: 4,187

Rep: Reputation: 354Reputation: 354Reputation: 354Reputation: 354
Try
Quote:
LOAD DATA INFILE '/tmp/new_userdata.txt' INTO TABLE users SET domain_id='19' FIELDS TERMINATED BY ',' (localpart,username,clear);
I believe SET and FIELDS qualify TABLE not the column list.

<edit>
You know, you could have avoided this whole problem by using this select:
Quote:
select '19',localpart,username,clear INTO OUTFILE '/tmp/new_userdata1.txt' FIELDS TERMINATED BY ',' FROM users where username LIKE '%domain.net.pk';
to create your file, and
Quote:
LOAD DATA INFILE '/tmp/new_userdata.txt' INTO TABLE users FIELDS TERMINATED BY ',' (domain_id,localpart,username,clear);
to read it back in.
</edit>

Last edited by PTrenholme; 01-07-2008 at 09:17 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
MYSQL Load data infile error slam Linux - Software 2 12-02-2012 11:26 PM
How to load data to tabel in MySql using script maheshdf Linux - Newbie 2 11-30-2006 03:06 AM
mysql - load data warning prabhatsoni Linux - Software 0 06-16-2005 06:08 AM
MySQL Load Data Separators joelhop Linux - Newbie 4 05-15-2004 10:26 PM
LOAD DATA INFILE error verokard Linux - Newbie 0 07-13-2003 11:02 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:18 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration