perl 在 ubuntu 20.04 上安装 DBD::mysql 失败

perl 在 ubuntu 20.04 上安装 DBD::mysql 失败

我已经在我的 ubuntu 20.04 笔记本电脑上安装了最新的 mysql 数据库。

接下来,我尝试安装编写 Perl 脚本来访问我的 mysql 数据库所需的所有 perl 模块。我启动了一个“sudo -i”会话,从中运行了“cpanb”命令

我成功使用 cpan 安装了 DBI 模块

但是当我尝试安装 DBD::mysql 模块时它失败了。

输出的最后一部分如下:

Configuring D/DV/DVEEDEN/DBD-mysql-4.050.tar.gz with Makefile.PL
Can't exec "mysql_config": No such file or directory at Makefile.PL line 89.

Cannot find the file 'mysql_config'! Your execution PATH doesn't seem
not contain the path to mysql_config. Resorting to guessed values!


PLEASE NOTE:

For 'make test' to run properly, you must ensure that the
database user 'root' 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 'root'@'localhost' identified by 's3kr1t';

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

perl Makefile.PL --testuser=username

Can't exec "mysql_config": No such file or directory at Makefile.PL line 603.
Can't find mysql_config. Use --mysql_config option to specify where mysql_config is located
Failed to determine directory of mysql.h. Use

  perl Makefile.PL --cflags=-I<dir>

to set this directory. For details see DBD::mysql::INSTALL,
section "C Compiler flags" or type

  perl Makefile.PL --help
Warning: No success on command[/usr/bin/perl Makefile.PL INSTALLDIRS=site]
  DVEEDEN/DBD-mysql-4.050.tar.gz
  /usr/bin/perl Makefile.PL INSTALLDIRS=site -- NOT OK
Failed during this command:
 DVEEDEN/DBD-mysql-4.050.tar.gz               : writemakefile NO '/usr/bin/perl Makefile.PL INSTALLDIRS=site' returned status 512

cpan[3]>     

答案1

经过谷歌搜索,我发现解决这个问题需要做以下事情

sudo apt-get install libmysqlclient-dev

现在我的基于 Perl 的 MySQL 脚本似乎运行良好。

相关内容