英文:
WARNING: MYSQL_OPT_RECONNECT is deprecated and will be removed in a future version
问题
根据你提供的信息,自MySQL 8.0.34版本开始,自动重新连接功能已被弃用,但你尝试在Perl脚本中禁用它仍然出现警告。你已经尝试了几种方法,但仍然无法摆脱警告。
建议你尝试以下方式来禁用重新连接功能:
-
更新Perl DBD::mysql模块到最新版本,以确保你使用的是最新版本的模块。
-
确保你在DBI连接选项中设置了
mysql_auto_reconnect
为0,就像你在代码中已经尝试的那样:
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} );
-
检查你的Perl脚本,确保没有其他地方在连接之后修改了
mysql_auto_reconnect
属性。你提到了mysql.pm
中的代码片段,确保它没有再次将mysql_auto_reconnect
设置为1。 -
如果你在连接字符串中添加了
reconnect=false
,请确保它的语法正确。这应该是在数据库连接字符串中,而不是在Perl代码中设置的。确保你的连接字符串类似于这样:
"DBI:mysql:database=$js_db_name;host=$js_db_host;reconnect=false"
- 检查你的MySQL客户端配置文件(通常是
/etc/my.cnf
),确保在[client]
部分中没有设置reconnect
选项。如果有,请删除它。
通过这些步骤,你应该能够成功禁用重新连接功能并摆脱警告。如果问题仍然存在,请确保你的MySQL服务器和客户端都是最新版本,并考虑咨询MySQL社区或Perl DBD::mysql模块的开发者获取更多帮助。
英文:
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?
答案1
得分: 11
DBD::mysql始终将MYSQL_OPT_RECONNECT设置为false,您的代码无法更改这一点。将其设置为任何值,包括false,都会引发错误。
参见:https://github.com/perl5-dbi/DBD-mysql/issues/354
英文:
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.
答案2
得分: 0
以下内容为我解决了问题,适用于Ubuntu 20.04.6 LTS(Focal Fossa):
sudo apt update
sudo apt install libdbd-mysql-perl
(正如原问题提问者和其他人在评论中建议的)
英文:
The following fixed the issue for me, on Ubuntu 20.04.6 LTS (Focal Fossa):
sudo apt update
sudo apt install libdbd-mysql-perl
(as suggested in comments from OP and others)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论