luxs has asked for the wisdom of the Perl Monks concerning the following question:

I have problems with DBI loosing connection to mysql becasue of the fork process

I do connect to MYSQL, do what ever i need to do

then i call to Parallel::ForkManager for job not related with MYSQL access and then try to work with MYSQL again and ... it is disconnected.

I do check with ping - it is disconnected.

The overall time spend in the fork processes is miserable - few seconds, so it is not time out At the moment i do disconnect before forks and then reconnect after forks... but it seems to be not ideal...

Yes, i do have $dbh->{mysql_auto_reconnect} = 1; but it does not help

Any idea why it can loose this connection?

Replies are listed 'Best First'.
Re: DBI lost connection
by marto (Cardinal) on Mar 05, 2020 at 11:34 UTC

    Are you using DBD::mysql or DBD::MariaDB? IIRC there was an issue with the former that was resolved in the latter.

      use DBI; my $dbh = DBI->connect( "DBI:mysql:database=".$config->{'mysql'}->{$db +}->{'d'}.";host=".$config->{'mysql'}->{$db}->{'h'}, $config->{'mysql'}->{$db}->{'u'}, $config->{'mysql'}->{$db}->{'p'}); $dbh->{'mysql_enable_utf8'} = 1; $dbh->do("SET NAMES 'utf8'"); $dbh->{mysql_auto_reconnect} = 1;
Re: DBI lost connection
by stevieb (Canon) on Mar 05, 2020 at 14:16 UTC

    It would be prudent and helpful if you'd show a full example including the fork code that breaks, so we can easily reproduce and test.

    I have code that works fine using the two, but it's very elaborate and would take too much time to post and explain, unless I could compare to what you've got.