ODBC详细配置

一.odbc相关配置

odbc详细配置描述

1.查看perl环境

perl默认已经安装

[root@localhost ~]# perl -v
This is perl 5, version 34, subversion 0 (v5.34.0) built for x86_64-linux-thread-multi
Copyright 1987-2021, Larry Wall

Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.

Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl".  If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
[root@localhost ~]#

2.DBI包下载及安装

2.1 下载DBI

https://metacpan.org/pod/DBI

选择需要下载的版本
在这里插入图片描述
在这里插入图片描述
点击下载然后上传到服务器或者wget方式下载

[root@localhost soft]# wget https://cpan.metacpan.org/authors/id/T/TI/TIMB/DBI-1.643.tar.gz

2.3 安装DBI

1.解压
[root@localhost soft]# tar -xvf DBI-1.643.tar.gz

[root@localhost soft]# tar -xvf DBI-1.643.tar.gz
DBI-1.643/
DBI-1.643/DBI.pm
DBI-1.643/dbipport.h
DBI-1.643/INSTALL
DBI-1.643/dbixs_rev.pl
DBI-1.643/Perl.xs
DBI-1.643/dbivport.h
DBI-1.643/LICENSE
DBI-1.643/dbi_sql.h
DBI-1.643/Changes
DBI-1.643/dbilogstrip.PL
...

2.安装
[root@localhost soft]# cd DBI-1.643
[root@localhost DBI-1.643]# perl Makefile.PL
[root@localhost DBI-1.643]# make
[root@localhost DBI-1.643]# make install

安装日志如下

# 进入目录
[root@localhost soft]# cd DBI-1.643
[root@localhost DBI-1.643]# perl Makefile.PL

*** Your LANG environment variable is set to 'en_US.UTF8'
*** This may cause problems for some perl installations.
*** If you get test failures, please try again with LANG unset.
*** If that then works, please email [email protected] with details
*** including the output of 'perl -V'

WARNING: Your GNU C 10.3.1 compiler is very old. Please upgrade it and rebuild perl.
Your perl was compiled with gcc (version 10.3.1), okay.
Creating test wrappers for DBD::Gofer:
...
Looks good

    I see you're using perl 5.034000 on x86_64-linux-thread-multi, okay.
    Remember to actually *read* the README file!
    Use  'make' to build the software (dmake or nmake on Windows).
    Then 'make test' to execute self tests.
    Then 'make install' to install the DBI and then delete this working
    directory before unpacking and building any DBD::* drivers.

Generating a Unix-style Makefile
Writing Makefile for DBI
Writing MYMETA.yml and MYMETA.json

[root@localhost DBI-1.643]# make
"/usr/bin/perl" -MExtUtils::Command -e 'mkpath' -- blib/lib/DBI
rm -f blib/lib/DBI/Changes.pm
## 执行make
[root@localhost DBI-1.643]# make
"/usr/bin/perl" -MExtUtils::Command -e 'mkpath' -- blib/lib/DBI
rm -f blib/lib/DBI/Changes.pm
cp Changes blib/lib/DBI/Changes.pm
cp lib/DBD/Gofer/Policy/classic.pm blib/lib/DBD/Gofer/Policy/classic.pm
cp lib/DBD/Gofer/Transport/corostream.pm blib/lib/DBD/Gofer/Transport/corostream.pm
cp lib/DBD/Gofer/Policy/pedantic.pm blib/lib/DBD/Gofer/Policy/pedantic.pm
cp lib/DBI/DBD.pm blib/lib/DBI/DBD.pm
cp lib/DBD/Gofer/Policy/rush.pm blib/lib/DBD/Gofer/Policy/rush.pm
cp lib/DBD/Gofer/Transport/Base.pm blib/lib/DBD/Gofer/Transport/Base.pm
cp lib/DBD/Gofer.pm blib/lib/DBD/Gofer.pm
cp Driver.xst blib/arch/auto/DBI/Driver.xst
cp lib/DBD/ExampleP.pm blib/lib/DBD/ExampleP.pm
cp lib/Bundle/DBI.pm blib/lib/Bundle/DBI.pm
cp lib/DBI/Const/GetInfo/ANSI.pm blib/lib/DBI/Const/GetInfo/ANSI.pm
cp lib/DBD/DBM.pm blib/lib/DBD/DBM.pm
cp lib/DBD/Gofer/Transport/pipeone.pm blib/lib/DBD/Gofer/Transport/pipeone.pm
cp lib/DBD/Gofer/Transport/stream.pm blib/lib/DBD/Gofer/Transport/stream.pm
cp lib/DBI/DBD/SqlEngine.pm blib/lib/DBI/DBD/SqlEngine.pm
cp lib/DBI/Const/GetInfo/ODBC.pm blib/lib/DBI/Const/GetInfo/ODBC.pm
cp dbivport.h blib/arch/auto/DBI/dbivport.h
cp dbi_sql.h blib/arch/auto/DBI/dbi_sql.h
cp dbixs_rev.pl blib/lib/dbixs_rev.pl
cp lib/DBD/File.pm blib/lib/DBD/File.pm
cp lib/DBD/File/HowTo.pod blib/lib/DBD/File/HowTo.pod
cp lib/DBI/DBD/Metadata.pm blib/lib/DBI/DBD/Metadata.pm
cp dbixs_rev.h blib/arch/auto/DBI/dbixs_rev.h
cp DBIXS.h blib/arch/auto/DBI/DBIXS.h
cp lib/DBD/NullP.pm blib/lib/DBD/NullP.pm
cp lib/DBD/Gofer/Policy/Base.pm blib/lib/DBD/Gofer/Policy/Base.pm
cp lib/DBI/DBD/SqlEngine/Developers.pod blib/lib/DBI/DBD/SqlEngine/Developers.pod
cp lib/DBI/DBD/SqlEngine/HowTo.pod blib/lib/DBI/DBD/SqlEngine/HowTo.pod
cp dbd_xsh.h blib/arch/auto/DBI/dbd_xsh.h
cp lib/DBD/File/Developers.pod blib/lib/DBD/File/Developers.pod
cp lib/DBD/Mem.pm blib/lib/DBD/Mem.pm
cp DBI.pm blib/lib/DBI.pm
cp lib/DBI/Gofer/Request.pm blib/lib/DBI/Gofer/Request.pm
cp lib/DBI/Const/GetInfoReturn.pm blib/lib/DBI/Const/GetInfoReturn.pm
cp lib/DBD/Sponge.pm blib/lib/DBD/Sponge.pm
cp lib/DBD/Gofer/Transport/null.pm blib/lib/DBD/Gofer/Transport/null.pm
cp dbipport.h blib/arch/auto/DBI/dbipport.h
cp lib/DBD/File/Roadmap.pod blib/lib/DBD/File/Roadmap.pod
cp lib/DBI/Const/GetInfoType.pm blib/lib/DBI/Const/GetInfoType.pm
cp Driver_xst.h blib/arch/auto/DBI/Driver_xst.h
cp lib/DBI/Gofer/Response.pm blib/lib/DBI/Gofer/Response.pm
cp lib/DBD/Proxy.pm blib/lib/DBD/Proxy.pm
cp lib/DBI/Gofer/Execute.pm blib/lib/DBI/Gofer/Execute.pm
cp lib/DBI/Gofer/Serializer/Base.pm blib/lib/DBI/Gofer/Serializer/Base.pm
cp lib/DBI/Gofer/Transport/stream.pm blib/lib/DBI/Gofer/Transport/stream.pm
cp lib/DBI/Gofer/Transport/Base.pm blib/lib/DBI/Gofer/Transport/Base.pm
cp lib/DBI/Profile.pm blib/lib/DBI/Profile.pm
cp lib/DBI/ProfileDumper.pm blib/lib/DBI/ProfileDumper.pm
cp lib/DBI/Util/_accessor.pm blib/lib/DBI/Util/_accessor.pm
cp lib/DBI/ProxyServer.pm blib/lib/DBI/ProxyServer.pm
cp lib/DBI/ProfileDumper/Apache.pm blib/lib/DBI/ProfileDumper/Apache.pm
cp lib/DBI/Gofer/Serializer/DataDumper.pm blib/lib/DBI/Gofer/Serializer/DataDumper.pm
cp lib/DBI/PurePerl.pm blib/lib/DBI/PurePerl.pm
cp lib/DBI/Util/CacheMemory.pm blib/lib/DBI/Util/CacheMemory.pm
cp lib/DBI/Gofer/Transport/pipeone.pm blib/lib/DBI/Gofer/Transport/pipeone.pm
cp lib/DBI/Gofer/Serializer/Storable.pm blib/lib/DBI/Gofer/Serializer/Storable.pm
cp lib/DBI/SQL/Nano.pm blib/lib/DBI/SQL/Nano.pm
cp lib/Win32/DBIODBC.pm blib/lib/Win32/DBIODBC.pm
cp lib/DBI/W32ODBC.pm blib/lib/DBI/W32ODBC.pm
cp lib/DBI/ProfileSubs.pm blib/lib/DBI/ProfileSubs.pm
cp lib/DBI/ProfileData.pm blib/lib/DBI/ProfileData.pm
Running Mkbootstrap for DBI ()
chmod 644 "DBI.bs"
"/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- DBI.bs blib/arch/auto/DBI/DBI.bs 644
"/usr/bin/perl" -p -e "s/~DRIVER~/Perl/g" ./Driver.xst > Perl.xsi
"/usr/bin/perl" "/usr/share/perl5/vendor_perl/ExtUtils/xsubpp"  -typemap '/usr/share/perl5/ExtUtils/typemap' -typemap '/opt/soft/DBI-1.643/typemap'  Perl.xs > Perl.xsc
mv Perl.xsc Perl.c
gcc -c   -D_REENTRANT -D_GNU_SOURCE -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/generic-hardened-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fwrapv -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -g   -DVERSION=\"1.643\" -DXS_VERSION=\"1.643\" -fPIC "-I/usr/lib64/perl5/CORE"  -W -Wall -Wpointer-arith -Wbad-function-cast -Wno-comment -Wno-sign-compare -Wno-cast-qual Perl.c
In file included from Perl.xs:7:
Perl.xs: In function ‘dbi_get_state’:
DBIXS.h:498:32: warning: cast between incompatible function types from ‘void (*)(PerlInterpreter *, CV *){
    
    aka ‘void (*)(struct interpreter *, struct cv *)} to ‘dbistate_t ** (*)(PerlInterpreter *){
    
    aka ‘struct dbistate_st ** (*)(struct interpreter *)} [-Wcast-function-type]
  498 |             dbi_state_lval_p = (_dbi_state_lval_t)CvXSUB(cv);               \
      |                                ^
DBIXS.h:506:27: note: in expansion of macro ‘_DBISTATE_DECLARE_COMMON’
  506 | # define DBISTATE_DECLARE _DBISTATE_DECLARE_COMMON
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~
Perl.xs:13:1: note: in expansion of macro ‘DBISTATE_DECLARE’
   13 | DBISTATE_DECLARE;
      | ^~~~~~~~~~~~~~~~
"/usr/bin/perl" "/usr/share/perl5/vendor_perl/ExtUtils/xsubpp"  -typemap '/usr/share/perl5/ExtUtils/typemap' -typemap '/opt/soft/DBI-1.643/typemap'  DBI.xs > DBI.xsc
mv DBI.xsc DBI.c
gcc -c   -D_REENTRANT -D_GNU_SOURCE -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/generic-hardened-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fwrapv -fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -g   -DVERSION=\"1.643\" -DXS_VERSION=\"1.643\" -fPIC "-I/usr/lib64/perl5/CORE"  -W -Wall -Wpointer-arith -Wbad-function-cast -Wno-comment -Wno-sign-compare -Wno-cast-qual DBI.c
DBI.xs: In function ‘dbi_ima_free’:
DBI.xs:244:46: warning: unused parameter ‘mg’ [-Wunused-parameter]
  244 | static int dbi_ima_free(pTHX_ SV* sv, MAGIC* mg)
      |                                       ~~~~~~~^~
DBI.xs: In function ‘sql_type_cast_svpv’:
DBI.xs:1943:65: warning: unused parameter ‘v’ [-Wunused-parameter]
 1943 | sql_type_cast_svpv(pTHX_ SV *sv, int sql_type, U32 flags, void *v)
      |                                                           ~~~~~~^
In file included from /usr/lib64/perl5/CORE/perl.h:5744,
                 from DBIXS.h:23,
                 from DBI.xs:13:
DBI.xs: In function ‘boot_DBI’:
DBI.xs:4477:42: warning: cast between incompatible function types from ‘dbistate_t ** (*)(PerlInterpreter *){
    
    aka ‘struct dbistate_st ** (*)(struct interpreter *)} to ‘void (*)(PerlInterpreter *, CV *){
    
    aka ‘void (*)(struct interpreter *, struct cv *)} [-Wcast-function-type]
 4477 |     (void) newXS("DBI::_dbi_state_lval", (XSUBADDR_t)_dbi_state_lval, __FILE__);
      |                                          ^
/usr/lib64/perl5/CORE/embed.h:400:42: note: in definition of macro ‘newXS’
  400 | #define newXS(a,b,c)  Perl_newXS(aTHX_ a,b,c)
      |                                          ^
rm -f blib/arch/auto/DBI/DBI.so
gcc  -shared -Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/generic-hardened-ld -L/usr/local/lib -fstack-protector-strong  DBI.o  -o blib/arch/auto/DBI/DBI.so  \
    -lperl   \

chmod 755 blib/arch/auto/DBI/DBI.so
"/usr/bin/perl" "-Iblib/arch" "-Iblib/lib" dbilogstrip.PL dbilogstrip
Extracted dbilogstrip from dbilogstrip.PL with variable substitutions.
"/usr/bin/perl" "-Iblib/arch" "-Iblib/lib" dbiprof.PL dbiprof
Extracted dbiprof from dbiprof.PL with variable substitutions.
"/usr/bin/perl" "-Iblib/arch" "-Iblib/lib" dbiproxy.PL dbiproxy
Extracted dbiproxy from dbiproxy.PL with variable substitutions.
cp dbilogstrip blib/script/dbilogstrip
"/usr/bin/perl" -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/dbilogstrip
cp dbiprof blib/script/dbiprof
"/usr/bin/perl" -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/dbiprof
cp dbiproxy blib/script/dbiproxy
"/usr/bin/perl" -MExtUtils::MY -e 'MY->fixin(shift)' -- blib/script/dbiproxy
Manifying 3 pod documents
Manifying 35 pod documents
Manifying 14 pod documents

[root@localhost DBI-1.643]# make install
"/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- DBI.bs blib/arch/auto/DBI/DBI.bs 644
Manifying 3 pod documents
Manifying 35 pod documents
Manifying 14 pod documents
Files found in blib/arch: installing files in blib/lib into architecture dependent library tree
Installing /usr/local/lib64/perl5/auto/DBI/DBI.so
Installing /usr/local/lib64/perl5/auto/DBI/dbd_xsh.h
Installing /usr/local/lib64/perl5/auto/DBI/dbivport.h
Installing /usr/local/lib64/perl5/auto/DBI/Driver_xst.h
Installing /usr/local/lib64/perl5/auto/DBI/dbi_sql.h
Installing /usr/local/lib64/perl5/auto/DBI/dbixs_rev.h
Installing /usr/local/lib64/perl5/auto/DBI/DBIXS.h
Installing /usr/local/lib64/perl5/auto/DBI/dbipport.h
Installing /usr/local/lib64/perl5/auto/DBI/Driver.xst
Installing /usr/local/lib64/perl5/dbixs_rev.pl
Installing /usr/local/lib64/perl5/DBI.pm
Installing /usr/local/lib64/perl5/DBD/Gofer.pm
Installing /usr/local/lib64/perl5/DBD/Sponge.pm
Installing /usr/local/lib64/perl5/DBD/DBM.pm
Installing /usr/local/lib64/perl5/DBD/Proxy.pm
Installing /usr/local/lib64/perl5/DBD/NullP.pm
Installing /usr/local/lib64/perl5/DBD/ExampleP.pm
Installing /usr/local/lib64/perl5/DBD/Mem.pm
Installing /usr/local/lib64/perl5/DBD/File.pm
Installing /usr/local/lib64/perl5/DBD/Gofer/Policy/classic.pm
Installing /usr/local/lib64/perl5/DBD/Gofer/Policy/Base.pm
Installing /usr/local/lib64/perl5/DBD/Gofer/Policy/rush.pm
Installing /usr/local/lib64/perl5/DBD/Gofer/Policy/pedantic.pm
Installing /usr/local/lib64/perl5/DBD/Gofer/Transport/null.pm
Installing /usr/local/lib64/perl5/DBD/Gofer/Transport/Base.pm
Installing /usr/local/lib64/perl5/DBD/Gofer/Transport/stream.pm
Installing /usr/local/lib64/perl5/DBD/Gofer/Transport/pipeone.pm
Installing /usr/local/lib64/perl5/DBD/Gofer/Transport/corostream.pm
Installing /usr/local/lib64/perl5/DBD/File/Developers.pod
Installing /usr/local/lib64/perl5/DBD/File/Roadmap.pod
Installing /usr/local/lib64/perl5/DBD/File/HowTo.pod
Installing /usr/local/lib64/perl5/Bundle/DBI.pm
Installing /usr/local/lib64/perl5/Win32/DBIODBC.pm
Installing /usr/local/lib64/perl5/DBI/Changes.pm
Installing /usr/local/lib64/perl5/DBI/PurePerl.pm
Installing /usr/local/lib64/perl5/DBI/ProfileDumper.pm
Installing /usr/local/lib64/perl5/DBI/ProxyServer.pm
Installing /usr/local/lib64/perl5/DBI/DBD.pm
Installing /usr/local/lib64/perl5/DBI/W32ODBC.pm
Installing /usr/local/lib64/perl5/DBI/Profile.pm
Installing /usr/local/lib64/perl5/DBI/ProfileSubs.pm
Installing /usr/local/lib64/perl5/DBI/ProfileData.pm
Installing /usr/local/lib64/perl5/DBI/DBD/Metadata.pm
Installing /usr/local/lib64/perl5/DBI/DBD/SqlEngine.pm
Installing /usr/local/lib64/perl5/DBI/DBD/SqlEngine/Developers.pod
Installing /usr/local/lib64/perl5/DBI/DBD/SqlEngine/HowTo.pod
Installing /usr/local/lib64/perl5/DBI/Gofer/Response.pm
Installing /usr/local/lib64/perl5/DBI/Gofer/Execute.pm
Installing /usr/local/lib64/perl5/DBI/Gofer/Request.pm
Installing /usr/local/lib64/perl5/DBI/Gofer/Serializer/Base.pm
Installing /usr/local/lib64/perl5/DBI/Gofer/Serializer/DataDumper.pm
Installing /usr/local/lib64/perl5/DBI/Gofer/Serializer/Storable.pm
Installing /usr/local/lib64/perl5/DBI/Gofer/Transport/Base.pm
Installing /usr/local/lib64/perl5/DBI/Gofer/Transport/stream.pm
Installing /usr/local/lib64/perl5/DBI/Gofer/Transport/pipeone.pm
Installing /usr/local/lib64/perl5/DBI/ProfileDumper/Apache.pm
Installing /usr/local/lib64/perl5/DBI/SQL/Nano.pm
Installing /usr/local/lib64/perl5/DBI/Util/CacheMemory.pm
Installing /usr/local/lib64/perl5/DBI/Util/_accessor.pm
Installing /usr/local/lib64/perl5/DBI/Const/GetInfoType.pm
Installing /usr/local/lib64/perl5/DBI/Const/GetInfoReturn.pm
Installing /usr/local/lib64/perl5/DBI/Const/GetInfo/ANSI.pm
Installing /usr/local/lib64/perl5/DBI/Const/GetInfo/ODBC.pm
Installing /usr/local/share/man/man1/dbiproxy.1
Installing /usr/local/share/man/man1/dbiprof.1
Installing /usr/local/share/man/man1/dbilogstrip.1
Installing /usr/local/share/man/man3/DBI::SQL::Nano.3pm
Installing /usr/local/share/man/man3/DBD::File::Roadmap.3pm
Installing /usr/local/share/man/man3/DBD::Gofer::Transport::Base.3pm
Installing /usr/local/share/man/man3/DBI::DBD::Metadata.3pm
Installing /usr/local/share/man/man3/DBI::ProfileSubs.3pm
Installing /usr/local/share/man/man3/DBD::Gofer::Policy::rush.3pm
Installing /usr/local/share/man/man3/DBI::Gofer::Transport::Base.3pm
Installing /usr/local/share/man/man3/DBI::Gofer::Execute.3pm
Installing /usr/local/share/man/man3/DBI::Const::GetInfoReturn.3pm
Installing /usr/local/share/man/man3/DBI::PurePerl.3pm
Installing /usr/local/share/man/man3/DBI::DBD::SqlEngine.3pm
Installing /usr/local/share/man/man3/DBI::Util::CacheMemory.3pm
Installing /usr/local/share/man/man3/DBI::DBD::SqlEngine::Developers.3pm
Installing /usr/local/share/man/man3/DBI::DBD::SqlEngine::HowTo.3pm
Installing /usr/local/share/man/man3/DBI::Gofer::Request.3pm
Installing /usr/local/share/man/man3/Win32::DBIODBC.3pm
Installing /usr/local/share/man/man3/DBI::Const::GetInfo::ODBC.3pm
Installing /usr/local/share/man/man3/DBD::File::Developers.3pm
Installing /usr/local/share/man/man3/DBI::ProfileDumper::Apache.3pm
Installing /usr/local/share/man/man3/DBD::File.3pm
Installing /usr/local/share/man/man3/DBI.3pm
Installing /usr/local/share/man/man3/DBD::Gofer::Policy::Base.3pm
Installing /usr/local/share/man/man3/DBI::Gofer::Serializer::DataDumper.3pm
Installing /usr/local/share/man/man3/DBD::Gofer::Transport::corostream.3pm
Installing /usr/local/share/man/man3/DBD::DBM.3pm
Installing /usr/local/share/man/man3/DBI::ProfileDumper.3pm
Installing /usr/local/share/man/man3/DBI::W32ODBC.3pm
Installing /usr/local/share/man/man3/DBI::Gofer::Response.3pm
Installing /usr/local/share/man/man3/DBD::Gofer::Policy::classic.3pm
Installing /usr/local/share/man/man3/DBD::Gofer::Transport::null.3pm
Installing /usr/local/share/man/man3/DBI::Gofer::Transport::pipeone.3pm
Installing /usr/local/share/man/man3/DBD::Mem.3pm
Installing /usr/local/share/man/man3/DBD::File::HowTo.3pm
Installing /usr/local/share/man/man3/DBI::ProxyServer.3pm
Installing /usr/local/share/man/man3/DBD::Gofer::Policy::pedantic.3pm
Installing /usr/local/share/man/man3/DBI::Gofer::Transport::stream.3pm
Installing /usr/local/share/man/man3/DBD::Gofer.3pm
Installing /usr/local/share/man/man3/Bundle::DBI.3pm
Installing /usr/local/share/man/man3/DBI::Gofer::Serializer::Storable.3pm
Installing /usr/local/share/man/man3/DBI::DBD.3pm
Installing /usr/local/share/man/man3/DBI::ProfileData.3pm
Installing /usr/local/share/man/man3/DBD::Proxy.3pm
Installing /usr/local/share/man/man3/DBI::Profile.3pm
Installing /usr/local/share/man/man3/DBD::Gofer::Transport::stream.3pm
Installing /usr/local/share/man/man3/DBI::Gofer::Serializer::Base.3pm
Installing /usr/local/share/man/man3/DBD::Sponge.3pm
Installing /usr/local/share/man/man3/DBI::Const::GetInfo::ANSI.3pm
Installing /usr/local/share/man/man3/DBI::Const::GetInfoType.3pm
Installing /usr/local/share/man/man3/DBD::Gofer::Transport::pipeone.3pm
Installing /usr/local/bin/dbilogstrip
Installing /usr/local/bin/dbiprof
Installing /usr/local/bin/dbiproxy
Appending installation info to /usr/lib64/perl5/perllocal.pod

2.3 验证DBI是否安装成功

# 执行如下操作,未报错则安装成功
[root@localhost DBI-1.643]# perl -e 'use DBI 1.643;'
# 验证不存在的版本,如下则报错
[root@localhost DBI-1.643]# perl -e 'use DBI 1.645;'
DBI version 1.645 required--this is only version 1.643 at -e line 1.
BEGIN failed--compilation aborted at -e line 1.

3.Test::Simple包下载及安装

1.下载Test::Simple

## 地址 https://metacpan.org/pod/Test::Simple
#[root@localhost soft]# wget https://cpan.metacpan.org/authors/id/E/EX/EXODIST/Test-Simple-1.302171.tar.gz

2.安装Test::Simple

[root@localhost soft]# tar -zxvf Test-Simple-1.302171.tar.gz
[root@localhost soft]# cd Test-Simple-1.302171
[root@localhost Test-Simple-1.302171]# perl Makefile.PL
[root@localhost Test-Simple-1.302171]# make
[root@localhost Test-Simple-1.302171]# make install

4.ExtUtils::MakeMaker包下载及安装

1.下载ExtUtils::MakeMaker

## 地址 https://metacpan.org/pod/ExtUtils::MakeMaker
#[root@localhost soft]# wget https://cpan.metacpan.org/authors/id/B/BI/BINGOS/ExtUtils-MakeMaker-7.44.tar.gz

2.安装ExtUtils::MakeMaker

[root@localhost soft]# tar -zxvf ExtUtils-MakeMaker-7.44.tar.gz
[root@localhost soft]# cd ExtUtils-MakeMaker-7.44
[root@localhost ExtUtils-MakeMaker-7.44]# perl Makefile.PL
[root@localhost ExtUtils-MakeMaker-7.44]# make
[root@localhost ExtUtils-MakeMaker-7.44]# make install

4.unixODBC包下载及安装

1.下载unixODBC 2.3.7

地址 http://www.unixodbc.org/
[github]  https://github.com/lurcher/unixODBC.git

在这里插入图片描述
在这里插入图片描述

2.安装unixODBC

[root@localhost soft]# tar -zxvf unixODBC-2.3.7.tar.gz
[root@localhost soft]# cd unixODBC-2.3.7
## ./configure 报错
#[root@localhost unixODBC-2.3.7]# aclocal
[root@localhost unixODBC-2.3.7]# autoheader
[root@localhost unixODBC-2.3.7]# automake --add-missing --copy
[root@localhost unixODBC-2.3.7]# autoconf
[root@localhost unixODBC-2.3.7]# ./configure --prefix=/usr/local/unixODBC

## 依然报错
#configure: creating ./config.status
#config.status: error: cannot find input file: `Makefile.in'
#configure: error: ./configure failed for libltdl


5. DBD::ODBC包下载及安装

如图可见,DBD::ODBC依赖DBI和Test::Simple包

# 地址 https://metacpan.org/pod/DBD::ODBC
#[root@localhost soft]# wget https://cpan.metacpan.org/authors/id/M/MJ/MJEVANS/DBD-ODBC-1.61.tar.gz

在这里插入图片描述

1.下载DBD::ODBC

地址 https://metacpan.org/pod/DBD::ODBC

2.安装DBD::ODBC

[root@localhost soft]# tar -zxvf DBD-ODBC-1.61.tar.gz
[root@localhost soft]# cd DBD-ODBC-1.61
[root@localhost DBD-ODBC-1.61]# perl Makefile.PL
[root@localhost DBD-ODBC-1.61]# make
[root@localhost DBD-ODBC-1.61]# make install

日志

Your LANG environment variable is set to "en_US.UTF8"
This is known to cause problems in some perl installations - even stopping
this Makefile.PL from running without errors. If you have problems please
try re-running with LANG unset or with the utf part of LANG removed.

You are using a Perl configured with threading enabled.
Please read the warnings in DBI about this.

You should also be aware that on non-Windows platforms ODBC drivers come
in two forms, thread-safe and non-thread-safe drivers and you may need
to make sure you are using the right one.

Press return to continue...
Looking for odbc_config in : nowhere
Looking for odbc_config in (PATH) /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
  odbc_config not found
Looking for iodbc-config in PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
  iodbc_config not found
odbc_config not found - ok, there are other things I can do
Still trying to guess ODBCHOME - looking for headers now
  trying /usr/include
  trying /usr/local/include
  trying /usr/pkg/include
  trying /usr/local/easysoft/unixODBC/include

I cannot find driver manager header files. Perhaps you need to install the
unixodbc-dev package or the iodbc-dev package


The DBD::ODBC module needs to link with an ODBC 'Driver Manager'.
(The Driver Manager, in turn, needs one or more database specific ODBC
drivers. The DBD::ODBC module does _not_ include any ODBC drivers!)

You need to indicate where your ODBC Driver Manager is installed.
You can do this by:

o setting the ODBCHOME environment variable
o running 'perl Makefile.PL -o odbcdir'
o adding path to odbc_config/iodbc_config to PATH

If you do not have an ODBC Driver Manager you should try to get hold of
the unixODBC packages for your system or build it from source (see
http://www.unixodbc.org). If you install driver manager packages you
need to include the "XXX-dev" package which includes the C header files.

安装报错(make操作,此时未安装unixODBC)

[root@localhost DBD-ODBC-1.61]# make
make: *** No targets specified and no makefile found.  Stop.

安装gcc-c++仍然无效

[root@localhost DBD-ODBC-1.61]# yum -y install gcc-c++

二.perl操作mysql数据库

处理过程:
1. 建立一个数据库连接
2. 通过建立的数据库连接,执行SQL语句
3. 执行SQL后获取返回的数据集
4. 在数据集中对记录进行处理,一般是一个循环的过程
5. 处理完毕,关闭数据库连接,释放资源

1. 数据库连接

# 主机地址
my $host = "localhost";
# 接口类型
my $driver = "mysql";
# 数据库       
my $database = "test_db";

# 驱动程序对象的句柄
my $dsn = "DBI:$driver:database=$database:$host";
## dsn或者设置如下,teradata为例
# 1.odbc配置文件定义名为Teradata或其他名称
# 2.my $dbcname="DBC";
# my $dsn="DBI:ODBC:Driver={Teradata};DBCName=$dbcname";
# 数据库用户名
my $userid = "dbuser";
# 数据库密码
my $password = "Pwd123";
# 连接数据库
my $dbh = DBI->connect($dsn, $userid, $password ) or die $DBI::errstr;
参数 说明
DBI 接口类型
mysql 数据库类型(必须小写)
test_db 数据库名称
localhost 主机地址

userid|用户名
password|密码

在连接过程中出现错误,connect则返回undef。因此需对错误和返回值进行检查。

2. 执行sql

# 预处理SQL语句
my $sth = $dbh->prepare("SELECT * FROM test_table");   
# 执行SQL操作 
$sth->execute(); 

连接上了数据库,获得了数据库连接句柄,就可以利用这个句柄来对数据库进行操作。
为了提高性能,DBI分两个步骤来做。先把SQL语句通过prepare方法提交到数据库,数据库为该语句分配执行资源,之后调用execute方法通知数据库执行该SQL语句。注意prepare方法是通过数据库连接句柄调用的,如果成功则返回一个该SQL的句柄,之后通过该SQL语句句柄调用execute执行SQL。 一般来说execute执行的都是返回数据的语句(例如SELECT语句)。反之如果执行INSERT、UPDATE、DELETE、CREATE TABLE等不需要返回数据的语句,则有一个更方便、快速的方法 $dbh->do(SQL语句),可以省去prepare的步骤。do方法返回的是受该SQL影响的记录数量。

$dbh->do(“UPDATE test_table SET name='HAHA')

参考资料:

https://blog.csdn.net/jiangshouzhuang/article/details/27485991
https://blog.csdn.net/paopaomm/article/details/80547412

猜你喜欢

转载自blog.csdn.net/u010895512/article/details/124621592
今日推荐