As I have seen here, Beginning with MySQL 8.0.34, the automatic reconnection feature is deprecated. I have a lot of Perl scripts that connect to a MySQL database with something like:
my $dbh = DBI->connect( "DBI:mysql:database=$db_name;host=$db_host",
$db_user, $db_pass, {'RaiseError' => 1,
mysql_enable_utf8 => 1} );
Which are now throwing a warning:
WARNING: MYSQL_OPT_RECONNECT is deprecated and will be removed in a future version.
I have tried changing the Perl code to:
my $dbh = DBI->connect( "DBI:mysql:database=$js_db_name;host=$js_db_host",
$js_db_user, $js_db_pass, {'RaiseError' => 1,
mysql_enable_utf8 => 1, mysql_auto_reconnect => 0} );
But the warning persists. I have tried adding reconnect=false
to the [client]
section of the config file at /etc/my.cnf
as suggested here. Also without success.
I have even tried to change the Perl DBI driver for MySQL which has code like this (mysql.pm
):
if ($this && ($ENV{MOD_PERL} || $ENV{GATEWAY_INTERFACE})) {
$this->{mysql_auto_reconnect} = 1;
}
To avoid setting the mysql_auto_reconnect
attribute to 1
. But that does not work either. There may be additional code but I would avoid changing a standard library if possible.
I have tried updating both DBI and DBD::mysql, but they seem to be up to date:
$ cpanm DBI
DBI is up to date. (1.643)
$ cpanm DBD::mysql
DBD::mysql is up to date. (4.050)
Any Perl script being executed that opens a connection throws the message to stderr.
The behaviour of DBD::mysql is documented as follows:
This attribute determines whether DBD::mysql will automatically reconnect to mysql if the connection be lost. This feature defaults to off; however, if either the GATEWAY_INTERFACE or MOD_PERL envionment variable is set, DBD::mysql will turn mysql_auto_reconnect on. Setting mysql_auto_reconnect to on is not advised if 'lock tables' is used because if DBD::mysql reconnect to mysql all table locks will be lost. This attribute is ignored when AutoCommit is turned off, and when AutoCommit is turned off, DBD::mysql will not automatically reconnect to the server. It is also possible to set the default value of the mysql_auto_reconnect attribute for the $dbh by passing it in the %attr hash for DBI-connect>. Note that if you are using a module or framework that performs reconnections for you (for example DBIx::Connector in fixup mode), this value must be set to 0.
But I was expecting to be able to bypass that by setting mysql_auto_reconnect => 0
. It is something that must be set explicitly because MySQL is now set to no reconnect by default:
$ mysql --help | egrep "^reconnect"
reconnect FALSE
Any ideas to disable the reconnect feature and get rid of the warning?
DBD::mysql always sets MYSQL_OPT_RECONNECT to false, there's nothing your code can do to change that. Setting it to any value, including false, emits the error.