perl 安装DB2::DBD

v

Technote (FAQ)

Question

How can my application written in Perl access my IBM DB2 Version 9.5 and above database for LUW?
Answer

Perl applications can access IBM DB2 data servers via the Perl DBI driver for DB2, DBD::DB2.
This document provides step-by-step instructions to install the DBD::DB2 Perl module and access data from DB2 data server.

Setting up the DBD::DB2 environment to access data in IBM DB2 data servers
Pre-requisites

    Linux: Perl version 5.8 or above
    Windows: ActivePerl version 5.8 or above
    DBI version 1.53 and above
    IBM DB2 client version 9 fp2 and above

Getting pre-requisites

    Perl: Download the latest perl for your respective platform from http://www.perl.org/get.html and install Perl

    DBI: Install the DBI module issuing the following command

    Perl 5.6: cpan install DBI

    Perl 5.10: cpan DBI

    On windows with Activestate perl you can install the binary version by issuing the following command

    ppm install DBI

    Note: Installing DBI requires internet access so it can download additional files.
    DB2 Client: DB2 client version v9fp2 or above is needed.
        If connecting to DB2 database server on a remote machine you will need to install the IBM Data Server Driver package (DS Driver) available at http://www.ibm.com/software/data/support/data-server-clients/index.html. More on DS Driver can be read at Infocentre
        If connecting to a database on local machine you will not need to install the DB2 client separately.
    Note: In further sections when referring to the installation location of the DB2 client,
        In case of DS Driver this will be the directory where you have untarred the odbc_cli driver in the package. for eg: $HOME/dsdriver/odbc_cli_driver/linuxamd64/clidriver
        In case of other type of DB2 clients this will be the location where DB2 is installed. For eg: /opt/ibm/db2/v97

Installing DBD::DB2 Driver
Windows - ActiveState Perl
Install the binary version of DBD::DB2 module by issuing the following commands

    32-bit

          ppm install http://www.bribes.org/perl/ppm/DBD-DB2.ppd
         
    64-bit

          ppm install http://www.bribes.org/perl/ppm64/DBD-DB2.ppd
         

Linux - CPAN installation
As for any cpan module issue the cpan command specifying DBD::DB2 as the module name, after setting the necessary environment variables as below

    $ export DB2_HOME=<location where db2 is installed>
    $ export DB2LIB=<location where db2 is installed>/lib[64/32]
        Based on your perl is 32-bit or 64-bit set the DB2LIB accordingly to lib32 or lib64 respectively
        Example, assuming DB2 is installed in /opt/ibm/db2/v105 and we are using 64-bit Perl use:
        $ export DB2_HOME=/opt/ibm/db2/v105
        $ export DB2LIB=/opt/ibm/db2/v105/lib64
        If you are using DS Driver then make sure you have selected and untarred the correct libraries (32 or 64 bit ) as per you perl's architecture and set DB2LIB to the lib directory
    $ cpan DBD::DB2

Refer to the section Architectural consideration for setting Environment variables for details on architectural considerations to note while setting necessary environment variables for successful installation and running of the perl DBD::DB2 driver
Installation from source - Applicable to all platforms
Pre-requisites
C compiler

    Windows: MingW compiler and the dmake utility or the VC compiler
    Linux: gcc compiler
    AIX:xlc compiler

Downloading the source
Download the latest DBD::DB2 driver source from http://search.cpan.org/~ibmtordb2/
Compiling and Installing the Driver
Untar the archive and issue the following commands

    $ export DB2_HOME=<location where db2 is installed>
    $ export DB2LIB=<location where db2 is installed>/lib[64/32]
        Based on your perl is 32-bit or 64-bit set the DB2LIB accordingly to lib32 or lib64 respectively
        If you are using DS Driver then make sure you have selected and untarred the correct libraries (32 or 64 bit ) as per you perl's architecture and set DB2LIB to the lib directory
    $ perl Makefile.PL
    $ make
    $ make install

    Note:
        If on Windows platform, the make command will respectively be dmake or nmake based on using MingW or the VC compiler
        Refer section Architectural consideration for setting Environment variables for details on architectural considerations
        Root access may be required for the make install command

原文地址:https://www.cnblogs.com/hzcya1995/p/13349784.html