You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

升级Windows版Strawberry Perl至5.40后无法找到DBD/mysql.pm

问题描述
  • 环境:Windows系统,Strawberry Perl从5.32版本升级至5.40版本
  • 现象:无法通过DBI连接MariaDB/MySQL数据库,相同脚本在Linux系统可正常运行
  • 报错信息:

install_driver(mysql) failed: Can't locate DBD/mysql.pm in @INC (you may need to install the DBD::mysql module) (@INC entries checked: C:/Strawberry/perl/site/lib C:/Strawberry/perl/vendor/lib C:/Strawberry/perl/lib) at (eval 6) line 3. Perhaps the DBD::mysql perl module hasn't been fully installed, or perhaps the capitalisation of 'mysql' isn't right. Available drivers: ADO, CSV, DBM, ExampleP, File, Gofer, Mem, ODBC, Pg, Proxy, SQLite, Sponge. at temp.pl line 12.

  • 检查结果:@INC目录中无DBD/mysql.pm,此前5.32版本默认内置该模块,无需额外配置即可使用
测试脚本
#!/usr/bin/perl

use strict;
use warnings;

use DBI;

my $dsn = "DBI:mysql:database=mydb;host=localhost";
my $username = "root";
my $password = "MariaDBRootPassword";

my $dbh = DBI->connect(
    "$dsn",
    "$username",
    "$password",
    {
        PrintError => 0,
        RaiseError => 1
    }
);

$dbh->disconnect();
解决方案建议
  • 手动安装DBD::mysql模块:
    打开Strawberry Perl自带的cpanm命令行工具,执行以下命令:
    cpanm DBD::mysql
    
    注意:安装前需确保Windows系统已安装MariaDB/MySQL的开发库(如libmysqlclient),若未安装,cpanm会尝试自动下载依赖完成安装。
  • 修复Strawberry Perl安装:
    重新运行Strawberry Perl 5.40的安装程序,选择「Repair」选项,修复可能缺失的内置模块。
  • 改用ODBC连接方案:
    若上述方法无效,可切换为ODBC连接方式,修改脚本中的DSN配置:
    my $dsn = "DBI:ODBC:Driver={MariaDB ODBC 3.1 Driver};Database=mydb;Server=localhost;UID=root;PWD=MariaDBRootPassword";
    
    需提前安装MariaDB ODBC驱动,并确保系统ODBC数据源配置正确。

内容的提问来源于stack exchange,提问作者Larry Menard

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 10:22:41