LinuxQuestions.org
Visit Jeremy's Blog.
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 11-10-2003, 06:58 PM   #1
lwsivad
LQ Newbie
 
Registered: Nov 2003
Posts: 5

Rep: Reputation: 0
Question Import simple file into MySQL


I need to import a very simply formatted flat file into a MySQL database. The flat file contains a single entry per line, username. I need to take the username (let's call the variable, $username) and put it into the following two ways:

INSERT INTO usergroup (Username, Groupname) VALUES ('$username', 'static');

INSERT INTO passcheck (Username, Attribute, Value) VALUES ('$username', 'Password', '$username');

The problem is my import file only has the username attribute. All the examples I find want the other data fields included in the file (I don't want them null, I need them defined as above). Is there a way to get a script to read each line, one at a time, then run the above commands to get the username into the database?

I have an AMP server where I can put the data in one record at a time (not good when there are several hundred records to imput). Is there a PHP solution maybe?

Thanks for any help.
 
Old 11-11-2003, 05:34 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
You could use awk (among others) to create the lines you want:

awk '{ print $1, "Password", $1}' import.sql

You might consider filling 2 tempfiles, one for the 'static' and one for the 'Password' lines and use these tempfiles to load the data into mysql. Could all be done from within 1 (bash/ksh) script.
 
  


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
import data to mysql server alaios Linux - Software 1 05-25-2005 12:37 AM
mysql data import bijuhpd Linux - Newbie 1 03-05-2005 08:01 AM
how to import images into mysql x2000koh Programming 6 02-03-2005 12:16 PM
Exporting MySQL error when trying to Import to another database. strez4prez Linux - Software 0 05-28-2004 11:43 AM
Import records to MySQL Database from a shell script chrisk5527 Linux - General 12 03-24-2004 09:49 PM

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

All times are GMT -5. The time now is 08:13 PM.

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