#!/usr/bin/perl use strict; use warnings; use DBI; my $file = 'test.sql'; my ($user,$pass,$db,$host) = ("xx","xx","xx","localhost"); my $dbh = DBI->connect("DBI:mysql:$db:$host",$user,$pass) or die $DBI::errstr; open my $fh,'<',$file or die $!; while(my $stmt = <$fh>){ $dbh->do($stmt) or die $dbh->errstr(); } close $fh;