Hi there,

I'm having a problem with MySQL with a Perl::DBI usage. I've turned it
upside-down and cannot find what it's related to (be it MySQL or DBI).

My script creates multiple databases and populates them with
tables. The problem appears when creating the second database (in the
foreach statement):

#
# Get a database connection to use to create new databases
#
my $tempDSN = 'DBI:mysql:database=test:host=localhost';
our $tempDBH =&DBI->connect($tempDSN,$login,$password)
        || die "Could not connect to test database: $! ";

#
# Go through a list of databases and create them one by one
#
foreach my $db ( keys(%$list_of_DBs) ) {

        #
        # Create a DB with the handler we have
        #
        my $create = $tempDBH->func('createdb',$db,'admin')
                ||die "Could not create database $db : $!";

        #
        # Connect to the newly created database
        #
        my $dbDSN = "DBI:mysql:database=$db:host=localhost";
        my $dbDBH = DBI->connect($dbDSN,$login,$password)
        || die "Could not connect to database $db : $!";

        #
        # Create a set of tables in this database
        #
        foreach my $table ( keys(%$list_of_tables) ) {
                $dbDBH->do("CREATE TABLE ... ");
        }

        #
        # Disconnect from the newly created database
        #
        $dbDBH->disconnect() || die "...";
}
#
# Disconnect from the temporary database connection
#
$tempDBH->disconnect();


So the first database is created with all it's table, but when I get to
the second, I get this error:
"Could not create database ..."
And when asking more detail with $DBI::errstr:
"ERROR: 2006 'MySQL server has gone away'"

I've really searched this down in my doc, on the net, and with
DBI->trace(5) but the only thing I figured out is that somehow the
temporary database connection is shut down by something without asking.

I've also tried creating the handler within the database loop, and then
it creates me exactly 96 databases and then stops telling me I've
reached the maximum connection number.

To do this, I use something like this in my first-level loop:

my $tempdb = DBI->install_driver('mysql');
my $create = $tempdb->func('createdb',$db,'localhost',$login,
$password,'admin');

When reading the MySQL log, I find this "create database" connection is
never closed. I've searched here and there but cannot find a way to
close it!!! (a $tempdb->disconnect() won't work -> Can't locate object
method "disconnect" via package "DBI:dr" ...)

Does somebody here have some experience about this?

Thanks,
Yannick


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to