Populating a database in mysql with a loader

  • Follow


Hello, I'm totally new to subject of database and I'm using mysql for
my project development. I would like to know what loader software I
can use for populating the mysql database. Also, are there good
tutorials that I can follow to use the loader ?
0
Reply Broli00 (348) 10/2/2008 2:36:45 AM

pereges wrote:
> Hello, I'm totally new to subject of database and I'm using mysql for
> my project development. I would like to know what loader software I
> can use for populating the mysql database. Also, are there good
> tutorials that I can follow to use the loader ?
> 

All kinds of ways - for instance the LOAD DATA command.  Or, if the data 
isn't in a format suitable for LOAD DATA, a short routine in your 
favorite programming language will do it.  That's what I do.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

0
Reply jstucklex (14410) 10/2/2008 3:51:55 AM


On Oct 1, 8:51=A0pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:

> All kinds of ways - for instance the LOAD DATA command. =A0Or, if the dat=
a
> isn't in a format suitable for LOAD DATA, a short routine in your
> favorite programming language will do it. =A0That's what I do.

Hello, I tried a simple example with load data but it seems like it
did not work properly.

I have this file called 'file.txt'. The contents are:

1 aaa
2 ffff
3 gggg
4 ppfep
5 abcdd

Now, here is how I created the table 'abcd' into which i want to load
this data:

create table abcd(    field1 int,
                       primary key(field1),
                       field2 varchar(100));

Next, I use this command:

load data local infile 'file.txt' into table abcd;

Then I use select * from abcd; to see the output and here's what i
saw:



field1     field2
1           NULL
2           NULL
3           NULL
4           NULL
5           NULL


Why is this happening ?Have I made a mistake somewhere ?

Also, I would like to know what are steps in writing a script in a
programming language to populate a data ? I would like to do this in
C.




0
Reply Broli00 (348) 10/2/2008 9:47:30 PM

pereges wrote:
> On Oct 1, 8:51 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> 
>> All kinds of ways - for instance the LOAD DATA command.  Or, if the data
>> isn't in a format suitable for LOAD DATA, a short routine in your
>> favorite programming language will do it.  That's what I do.
> 
> Hello, I tried a simple example with load data but it seems like it
> did not work properly.
> 
> I have this file called 'file.txt'. The contents are:
> 
> 1 aaa
> 2 ffff
> 3 gggg
> 4 ppfep
> 5 abcdd
> 
> Now, here is how I created the table 'abcd' into which i want to load
> this data:
> 
> create table abcd(    field1 int,
>                        primary key(field1),
>                        field2 varchar(100));
> 
> Next, I use this command:
> 
> load data local infile 'file.txt' into table abcd;
> 
> Then I use select * from abcd; to see the output and here's what i
> saw:
> 
> 
> 
> field1     field2
> 1           NULL
> 2           NULL
> 3           NULL
> 4           NULL
> 5           NULL
> 
> 
> Why is this happening ?Have I made a mistake somewhere ?
>

That's because the default field separator for LOAD FILE is a tab, and 
it looks like you have a space.  So it loads the numeric portion of the 
data into field1 and skips the rest.

See http://dev.mysql.com/doc/refman/5.1/en/load-data.html.


> Also, I would like to know what are steps in writing a script in a
> programming language to populate a data ? I would like to do this in
> C.
> 
> 

The same as with any other database:

  1. Connect to the database server
  2. Select the correct database.
  3. Loop:
     3a. Read a line from the file
     3b. Parse the line into separate variables
     3c. Insert the data into the database
  4. Close the database.

See the MySQL doc at http://dev.mysql.com/doc/refman/5.1/en/.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

0
Reply jstucklex (14410) 10/2/2008 10:02:57 PM

3 Replies
37 Views

(page loaded in 0.105 seconds)

Similiar Articles:





7/15/2012 6:15:12 PM


Reply: