#! /usr/bin/perl # Untested, but ought to be close, if not right on. # Assumes CSV file is called 'people', in /home/me/db. use strict ; use warnings ; $|++ ; use DBI ; my $dbh = DBI->connect( "DBI:CSV:f_dir=/home/me/db;csv_eol=\n", { RaiseError => 1 } ) ; # Get the data out of the CSV file. my $sth = $dbh->prepare( 'SELECT * FROM people' ) ; $sth->execute ; my $data = $sth->fetchall_arrayref( {} ) ; $dbh->disconnect ; $dbh = DBI->connect( "DBI:mysql:my_db", 'username', 'password', { RaiseError => 1 } ) ; # Dump into the MySQL table. $sth = $dbh->prepare( <<'END_OF_SQL' ) ; INSERT INTO my_people ( ID, Name, Memo ) VALUES ( ?, ?, ? ) END_OF_SQL foreach ( @$data ) { $sth->execute( $_->{'ID'}, $_->{'Name'}, $_->{'Memo'} ) ; } __END__