Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 11-29-2006, 05:10 AM   #1
LQ Newbie
Registered: Nov 2006
Posts: 10

Rep: Reputation: 0
Wink How to load data to tabel in MySql using script


I want to upload some date to table in my MySQL database. Now I am using perl coding to do it. Can some one give me and idea how to do it using shell script.

my sql statement as follows,

LOAD DATA LOCAL INFILE '/Scripts/tableupload//20051101.cdr.txt' INTO TABLE ppscdr_200511 

Last edited by maheshdf; 11-29-2006 at 05:12 AM.
Old 11-29-2006, 09:06 AM   #2
Registered: May 2004
Location: Iowa USA
Distribution: CentOS
Posts: 419

Rep: Reputation: 30
You could just call the mysql client with -e and pass it the commands you want executed. For example:
mysql -e "USE DATABASE_NAME; LOAD DATA LOCAL INFILE '/Scripts/tableupload//20051101.cdr.txt' INTO TABLE ppscdr_200511 FIELDS TERMINATED BY '|';"
This assumes that the script is running as a user with permissions to DATABASE_NAME, of course.

Hope that helps.
Old 11-30-2006, 04:06 AM   #3
LQ Newbie
Registered: Nov 2006
Posts: 10

Original Poster
Rep: Reputation: 0
Hi thanks for the help. It is working fine. I have another question.
How can I use a varible defined in the shell inside sql statement.

For example see the following, it dosent work,


file_name = 20051101

mysql -e "USE DATABASE_NAME; LOAD DATA LOCAL INFILE '/Scripts/tableupload/$file_name.cdr.txt' INTO TABLE $file_name
Give me an idea to fix it.

Last edited by maheshdf; 11-30-2006 at 04:08 AM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 warning prabhatsoni Linux - Software 0 06-16-2005 07:08 AM
script for emailing mysql data MrJoshua Programming 5 06-14-2005 02:32 PM
MySQL Load Data Separators joelhop Linux - Newbie 4 05-15-2004 11:26 PM
LOAD DATA INFILE error verokard Linux - Newbie 0 07-14-2003 12:02 AM
i am tryin to write a script that will send data to MySQL rhuser Programming 7 03-06-2003 04:17 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:16 AM.

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