As the others have said, Perl is ideal for this type of thing. I've done many successful projects using Perl and MySQL. I'll go into some detail here.
First, make sure you get the DBD module for MySQL from CPAN, in addition to the DBI module.
Then, in your script you want to do something like this:
# database API
use DBI;
# Database Variables
my $db_type = 'mysql'; # RDMS controlling the database
my $db_database = 'name'; # name of the database
my $db_username = 'user'; # username to access this database
my $db_password = 'pass'; # password to access this database
# Connect to your database
my $drh=DBI->install_driver($db_type);
my $dbh=$drh->connect($db_username,$db_database,$db_password) || die "Error connecting to database: $DBI::errstr\n";
# Do a select with @array holding the result
my $selecttable = $dbh->prepare("SELECT fields FROM table WHERE condition"

;
$selecttable->execute || die "Could not query database: $DBI::errstr.";
my @array = $selecttable->fetchrow;
$selecttable->finish;
# Do an insert
my $insertion = $dbh->prepare("UPDATE table SET field=value WHERE conditions"

;
$insertion->execute || die "Could not insert: $DBI::errstr.";
$insertion->finish;
# Et cetera. You can do lots of stuff through the DBI
# module, though I find it easier to actually build my
# database in the mysql terminal program. I just populate
# it and query it dynamically with my website.
# At the end of your script, you have to
$dbh->disconnect;
Sincerely,
Tom Anderson
CEO, Order amid Chaos, Inc.