Why does Perl reuse the same MySQL connection in this Munin script?

93 views Asked by At

I have modified the script mysql_ from Munin, so that the function do_connect looks like this:

sub db_connect {
    my $dsn =     "$config{dsn};mysql_socket=$config{mysqlsocket};mysql_connect_timeout=5;";

    return DBI->connect($dsn, $config{user}, $config{password}, {
        RaiseError       => 1,
        PrintError       => 0,
        FetchHashKeyName => 'NAME_lc',
    });
}

I have configured plugins-conf to set different values for the socket reflected in the environment variable mysqlsocket. So, each instance has its own value for env.mysqlsocket. When I run my instances with

$ for i in a b c; do munin-run mysql_${i}_innodb_rows; done

then the first one that connects (a in this order) opens a connection which is used by the subsequent ones, instead of their sockets. The connection strings are correct, they really change.

The DBI->connect is not executed. I can prove this by setting the socket filenames to non-existent files; it reuses the same connection again.

I wonder, since these are independent processes of a symlinked script.

How can I force my Perl script to open a new connection anyway?

1

There are 1 answers

2
Ipor Sircer On

Use the manual:

$dsn->disconnect;