2.14. Perl Installation Notes

MySQL 5.0

2.14. Perl Installation Notes

Perl support for MySQL is provided by means of the / client interface. The interface requires Perl 5.6.1 or later. It does not work if you have an older version of Perl.

If you want to use transactions with Perl DBI, you need to have version 1.2216 or newer. 2.9003 or newer is recommended.

If you are using the MySQL 4.1 or newer client library, you must use 2.9003 or newer.

Perl support is not included with MySQL distributions. You can obtain the necessary modules from http://search.cpan.org for Unix, or by using the ActiveState ppm program on Windows. The following sections describe how to do this.

Perl support for MySQL must be installed if you want to run the MySQL benchmark scripts. See Section 7.1.4, “The MySQL Benchmark Suite”.

2.14.1. Installing Perl on Unix

MySQL Perl support requires that you have installed MySQL client programming support (libraries and header files). Most installation methods install the necessary files. However, if you installed MySQL from RPM files on Linux, be sure that you've installed the developer RPM. The client programs are in the client RPM, but client programming support is in the developer RPM.

If you want to install Perl support, the files you need can be obtained from the CPAN (Comprehensive Perl Archive Network) at http://search.cpan.org.

The easiest way to install Perl modules on Unix is to use the module. For example:

shell> 
cpan> 
cpan> 

The installation runs a number of tests. These tests attempt to connect to the local MySQL server using the default username and password. (The default username is your login name on Unix, and on Windows. The default password is “no password.”) If you cannot connect to the server with those values (for example, if your account has a password), the tests fail. You can use to ignore the failed tests.

requires the module. It may be installed; if not, you should install it before installing .

It is also possible to download the module distributions in the form of compressed tar archives and build the modules manually. For example, to unpack and build a DBI distribution, use a procedure such as this:

  1. Unpack the distribution into the current directory:

    shell> .tar.gz | tar xvf -
    

    This command creates a directory named .

  2. Change location into the top-level directory of the unpacked distribution:

    shell> 
    
  3. Build the distribution and compile everything:

    shell> 
    shell> 
    shell> 
    shell> 
    

The make test command is important because it verifies that the module is working. Note that when you run that command during the installation to exercise the interface code, the MySQL server must be running or the test fails.

It is a good idea to rebuild and reinstall the distribution whenever you install a new release of MySQL, particularly if you notice symptoms such as that all your scripts fail after you upgrade MySQL.

If you do not have access rights to install Perl modules in the system directory or if you want to install local Perl modules, the following reference may be useful: http://servers.digitaldaze.com/extensions/perl/modules.html#modules

Look under the heading “Installing New Modules that Require Locally Installed Modules.

2.14.2. Installing ActiveState Perl on Windows

On Windows, you should do the following to install the MySQL module with ActiveState Perl:

  1. Get ActiveState Perl from http://www.activestate.com/Products/ActivePerl/ and install it.

  2. Open a console window (a “DOS window”).

  3. If necessary, set the variable. For example, you might try a setting like this:

    set HTTP_proxy=my.proxy.com:3128
    
  4. Start the PPM program:

    C:\> 
    
  5. If you have not previously done so, install :

    ppm> install DBI
    
  6. If this succeeds, run the following command:

    ppm> 
      
    

This procedure should work with ActiveState Perl 5.6 or newer.

If you cannot get the procedure to work, you should install the MyODBC driver instead and connect to the MySQL server through ODBC:

use DBI;
$dbh= DBI->connect("DBI:ODBC:$dsn",$user,$password) ||
  die "Got error $DBI::errstr when connecting to $dsn\n";

2.14.3. Problems Using the Perl DBI/DBD Interface

If Perl reports that it cannot find the module, the problem is probably that Perl cannot locate the shared library. You should be able to fix this problem by one of the following methods:

  • Compile the distribution with rather than .

  • Copy to the directory where your other shared libraries are located (probably or ).

  • Modify the options used to compile to reflect the actual location of .

  • On Linux, you can add the pathname of the directory where is located to the file.

  • Add the pathname of the directory where is located to the environment variable. Some systems use instead.

Note that you may also need to modify the options if there are other libraries that the linker fails to find. For example, if the linker cannot find because it is in and the link command specifies , change the option to or add to the existing link command.

If you get the following errors from , you are probably using gcc (or using an old binary compiled with gcc):

/usr/bin/perl: can't resolve symbol '__moddi3'
/usr/bin/perl: can't resolve symbol '__divdi3'

Add to the link command when the library gets built (check the output from make for when you compile the Perl client). The option should specify the pathname of the directory where is located on your system.

Another cause of this problem may be that Perl and MySQL are not both compiled with gcc. In this case, you can solve the mismatch by compiling both with gcc.

You may see the following error from when you run the tests:

t/00base............install_driver(mysql) failed:
Can't load '../blib/arch/auto/DBD/mysql/mysql.so' for module DBD::mysql:
../blib/arch/auto/DBD/mysql/mysql.so: undefined symbol:
uncompress at /usr/lib/perl5/5.00503/i586-linux/DynaLoader.pm line 169.

This means that you need to include the compression library on the link line. That can be done by changing the following line in the file :

$sysliblist .= " -lm";

Change that line to:

$sysliblist .= " -lm -lz";

After this, you must run make realclean and then proceed with the installation from the beginning.

If you want to install DBI on SCO, you have to edit the in DBI- and each subdirectory. Note that the following assumes gcc 2.95.2 or newer:

OLD:                                  NEW:
CC = cc                               CC = gcc
CCCDLFLAGS = -KPIC -W1,-Bexport       CCCDLFLAGS = -fpic
CCDLFLAGS = -wl,-Bexport              CCDLFLAGS =

LD = ld                               LD = gcc -G -fpic
LDDLFLAGS = -G -L/usr/local/lib       LDDLFLAGS = -L/usr/local/lib
LDFLAGS = -belf -L/usr/local/lib      LDFLAGS = -L/usr/local/lib

LD = ld                               LD = gcc -G -fpic
OPTIMISE = -Od                        OPTIMISE = -O1

OLD:
CCCFLAGS = -belf -dy -w0 -U M_XENIX -DPERL_SCO5 -I/usr/local/include

NEW:
CCFLAGS = -U M_XENIX -DPERL_SCO5 -I/usr/local/include

These changes are necessary because the Perl dynaloader does not load the modules if they were compiled with icc or cc.

If you want to use the Perl module on a system that does not support dynamic linking (such as SCO), you can generate a static version of Perl that includes and . The way this works is that you generate a version of Perl with the code linked in and install it on top of your current Perl. Then you use that to build a version of Perl that additionally has the code linked in, and install that.

On SCO, you must have the following environment variables set:

LD_LIBRARY_PATH=/lib:/usr/lib:/usr/local/lib:/usr/progressive/lib

Or:

LD_LIBRARY_PATH=/usr/lib:/lib:/usr/local/lib:/usr/ccs/lib:\
    /usr/progressive/lib:/usr/skunk/lib
LIBPATH=/usr/lib:/lib:/usr/local/lib:/usr/ccs/lib:\
    /usr/progressive/lib:/usr/skunk/lib
MANPATH=scohelp:/usr/man:/usr/local1/man:/usr/local/man:\
    /usr/skunk/man:

First, create a Perl that includes a statically linked module by running these commands in the directory where your distribution is located:

shell> 
shell> 
shell> 
shell> 

Then you must install the new Perl. The output of make perl indicates the exact make command you need to execute to perform the installation. On SCO, this is make -f Makefile.aperl inst_perl MAP_TARGET=perl.

Next, use the just-created Perl to create another Perl that also includes a statically linked by running these commands in the directory where your distribution is located:

shell> 
shell> 
shell> 
shell> 

Finally, you should install this new Perl. Again, the output of make perl indicates the command to use.