使用 cpanm 在 Mac 中安装 DBD::mysql 失败

Fail in installing DBD::mysql in Mac using cpanm

我总是安装失败 DBD::mysql。 我使用的命令是:

brew install mysql
cpanm DBD::mysql

我得到的错误是:

--> Working on DBD::mysql
Fetching http://www.cpan.org/authors/id/D/DV/DVEEDEN/DBD-mysql-4.050.tar.gz ... OK
Configuring DBD-mysql-4.050 ... N/A
! Configure failed for DBD-mysql-4.050. See /Users/jeji/.cpanm/work/1642350924.83890/build.log for details.

因此,我通过日志文件进行了检查。我的日志文件读取:

cpanm (App::cpanminus) 1.9018 on perl 5.030003 built for darwin-thread-multi-2level
Work directory is /Users/jeji/.cpanm/work/1642350924.83890
You have make /usr/bin/make
You have LWP: 6.44
You have LWP::Protocol::https: 6.07
You have /usr/bin/tar: bsdtar 3.5.1 - libarchive 3.5.1 zlib/1.2.11 liblzma/5.0.5 bz2lib/1.0.8 
You have /usr/bin/unzip
Searching DBD::mysql () on cpanmetadb ...
--> Working on DBD::mysql
Fetching http://www.cpan.org/authors/id/D/DV/DVEEDEN/DBD-mysql-4.050.tar.gz
-> OK
Unpacking DBD-mysql-4.050.tar.gz
Entering DBD-mysql-4.050
Checking configure dependencies from META.json
Checking if you have DBI 1.609 ... Yes (1.643)
Checking if you have Data::Dumper 0 ... Yes (2.174)
Checking if you have ExtUtils::MakeMaker 6.58 ... Yes (7.34)
Checking if you have Devel::CheckLib 1.09 ... Yes (1.14)
Configuring DBD-mysql-4.050
Running Makefile.PL


PLEASE NOTE:

For 'make test' to run properly, you must ensure that the
database user 'jeji' can connect to your MySQL server
and has the proper privileges that these tests require such
as 'drop table', 'create table', 'drop procedure', 'create procedure'
as well as others.

mysql> grant all privileges on test.* to 'jeji'@'localhost' identified by 's3kr1t';

You can also optionally set the user to run 'make test' with:

perl Makefile.PL --testuser=username

I will use the following settings for compiling and testing:

  cflags        (mysql_config) = -I/usr/local/Cellar/mysql/8.0.27_1/include/mysql
  embedded      (guessed     ) = 
  ldflags       (guessed     ) = 
  libs          (mysql_config) = -L/usr/local/Cellar/mysql/8.0.27_1/lib -lmysqlclient -lz -lzstd -lssl -lcrypto -lresolv
  mysql_config  (guessed     ) = mysql_config
  nocatchstderr (default     ) = 0
  nofoundrows   (default     ) = 0
  nossl         (default     ) = 0
  testdb        (default     ) = test
  testhost      (default     ) = 
  testpassword  (default     ) = 
  testport      (default     ) = 
  testsocket    (default     ) = 
  testuser      (guessed     ) = jeji

To change these settings, see 'perl Makefile.PL --help' and
'perldoc DBD::mysql::INSTALL'.

Checking if libs are available for compiling...
Can't link/include C library 'ssl', 'crypto', aborting.
-> N/A
Checking dependencies from META.json ...
Checking if you have Time::HiRes 0 ... Yes (1.9760)
Checking if you have ExtUtils::MakeMaker 0 ... Yes (7.34)
Checking if you have Test::Deep 0 ... Yes (1.130)
Checking if you have Test::Simple 0.90 ... Yes (1.302162)
Checking if you have bigint 0 ... Yes (0.51)
Checking if you have DBI 1.609 ... Yes (1.643)
-> FAIL Configure failed for DBD-mysql-4.050. See /Users/jeji/.cpanm/work/1642350924.83890/build.log for details.

我确实认为'不能 link/include C 库 'ssl'、'crypto',正在中止。 -> N/A' 是导致问题的部分,但我不知道如何解决该问题。 任何解决方案都会很棒!

提前致谢:)

这是我在 macOS 上安装 DBD::mysql 的方法:

cpan -T DBI

sudo cpanm DBD::mysql -n \
 --configure-args="--libs='-L/usr/local/opt/openssl/lib -lssl -lcrypto -lperconaserverclient'"

我安装的是 Percona Server 而不是 MySQL,因此您可能不需要最后一个选项。