当前位置: 首页 > 工具软件 > Perl DBI > 使用案例 >

【Perl】Linux下安装perl的DBI和DBD模块

贾建茗
2023-12-01

一、安装步骤

先安装DBI,再安装DBD

1.安装前置包

如果有,请忽略

yum install perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
yum -y install perl-Digest-MD5

2.确定是否存在环境变量 $LD_LIBRARY_PATH,没有的话需要配置

[root@host-10-227-222-144 DBI-1.636]# $LD_LIBRARY_PATH 
bash: /tycj/app/oracle_client/product/11.2.0/client_1/lib:/tycj/app/oracle_client/product/11.2.0/client_1/jdbc/lib: No such file or directory

配置参考:

ORACLE_BASE=/u01/app/oracle_client
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/client_1
LD_LIBRARY_PATH=${ORACLE_HOME}/lib:${ORACLE_HOME}/jdbc/lib
export PATH=$ORACLE_HOME/bin:$PATH
export LANG=en_US.UTF-8
#export LANG=C
export LD_LIBRARY_PATH
export TMOUT=6000
export ORACLE_BASE
export ORACLE_HOME
export ORACLE_SID=orcl

3.确认本机perl存在,没有的话,还需要安装perl

perl -version

[root@host]# perl -version
This is perl 5, version 16, subversion 3 (v5.16.3) built for x86_64-linux-thread-multi
(with 29 registered patches, see perl -V for more detail)
Copyright 1987-2012, Larry Wall

4.安装前要修改oracle_client/product/11.2.0/client_1/lib目录下两个软连接

cd /home/manager/oracle_client/product/11.2.0/client_1/lib
rm -rf libclntsh.so
rm -rf libclntsh.so.10.1
ln -s   /home/manager/oracle_client/product/11.2.0/client_1/lib/libclntsh.so.11.1 /home/manager/oracle_client/product/11.2.0/client_1/lib/libclntsh.so
ln -s   /home/manager/oracle_client/product/11.2.0/client_1/lib/libclntsh.so /home/manager/oracle_client/product/11.2.0/client_1/lib/libclntsh.so.10.1

5.安装DBI

#进DBI目录
#建议用root

cd DBI-1.636
#依次执行:
perl Makefile.PL
make
make test(或不执行)
make install

6.安装DBD

#进DBD目录
#建议用root

cd DBI-1.636
#依次执行:
perl Makefile.PL
make
make test(或不执行)
make install

二、报错解决:

1.Can’t locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 11.

BEGIN failed–compilation aborted at Makefile.PL line 11.
解决:
缺包

[root]yum install perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker

2.Can’t locate Digest/MD5.pm in @INC (@INC contains

缺包

yum -y install perl-Digest-MD5

3.cannot find -lclntsh

/usr/bin/ld: cannot find -lclntsh
collect2: ld returned 1 exit status
make: *** [blib/arch/auto/DBD/Oracle/Oracle.so] Error 1

就是没有更改软连接:

cd /home/manager/oracle_client/product/11.2.0/client_1/lib
rm -rf libclntsh.so
rm -rf libclntsh.so.10.1
ln -s   /home/manager/oracle_client/product/11.2.0/client_1/lib/libclntsh.so.11.1 /home/manager/oracle_client/product/11.2.0/client_1/lib/libclntsh.so
ln -s   /home/manager/oracle_client/product/11.2.0/client_1/lib/libclntsh.so /home/manager/oracle_client/product/11.2.0/client_1/lib/libclntsh.so.10.1

4.Can’t load ‘/usr/local/lib64/perl5/auto/DBD/Oracle/Oracle.so’ for module DBD

这个报错据说是环境变量原因,但具体不知道,按大佬说的这样处理的确解决了

vi  /etc/ld.so.conf.d/oracle-x86_64.conf 
echo "$ORACLE_HOME/lib" >> /etc/ld.so.conf.d/oracle-x86_64.conf && ldconfig 

DBI/DBD下载连接:

DBI-1.636.tar.gz
DBD-Oracle-1.75_2.tar.gz

参考文章:

Linux下安装Perl和Perl的DBI模块
Linux下安装DBI和DBD
Can’t locate ExtUtils/MakeMaker.pm in @INC 错误的解决方式
关于编译/usr/bin/ld: cannot find -lclntsh -小小经验分享
install_driver(Oracle) failed: Can’t load ‘/usr/local/lib/perl5/auto/DBD/Oracle/Oracle.so’ for module DBD::Oracle: libocci.so.11.1
install_driver(Oracle) failed: Can’t load `…/DBD/Oracle/Oracle.so’ for module DBD::Oracle

 类似资料: