Perl Installation Comments

Installing Perl on Unix

Perl support for MySQL is provided by means of the DBI/DBD client interface. See Section 8.2. The Perl DBD/DBI client code requires Perl Version 5.004 or later. The interface will not work if you have an older version of Perl.

MySQL Perl support also requires that you’ve installed MySQL client programming support. If you installed MySQL from RPM files, client programs are in the client RPM, but client programming support is in the developer RPM. Make sure you’ve installed the latter RPM.

As of Version 3.22.8, Perl support is distributed separately from the main MySQL distribution. If you want to install Perl support, the files you will need can be obtained from http://www.mysql.com/Downloads/Contrib/.

The Perl distributions are provided as compressed tar archives and have names like MODULE-VERSION.tar.gz, where MODULE is the module name and VERSION is the version number. You should get the Data-Dumper, DBI, and Msql-Mysql-modules distributions and install them in that order. The installation procedure is shown next. The example shown is for the Data-Dumper module, but the procedure is the same for all three distributions:

  1. Unpack the distribution into the current directory:

    shell> gunzip < Data-Dumper-VERSION.tar.gz | tar xvf -

    This command creates a directory named Data-Dumper-VERSION.

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

    shell> cd Data-Dumper-VERSION
  3. Build the distribution and compile everything:

    shell> perl Makefile.PL
    shell> make
    shell> make test
    shell> make install

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

It is a good idea to rebuild and reinstall the Msql-Mysql-modules distribution whenever you install a new release of MySQL, particularly if you notice symptoms such as all your DBI scripts dumping core after you upgrade MySQL.

If you don’t have the right to install Perl modules in the system directory or if you do install local Perl modules, the following reference may help you:

http://www.iserver.com/support/contrib/perl5/modules.html

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

Installing ActiveState Perl on Windows

To install the MySQL DBD module with ActiveState Perl on Windows, you should do the following:

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

  • Open a DOS shell.

  • If required, set the HTTP_proxy variable. For example, you might try:

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

    C:\> c:\perl\bin\ppm.pl
  • If you have not already done so, install DBI:

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

    install \
    ftp://ftp.de.uu.net/pub/CPAN/authors/id/JWIED/DBD-mysql-1.2212.x86.ppd

This should work at least with ActiveState Perl Version 5.6.

If you can’t get this to work, you should instead install the MyODBC driver and connect to MySQL server through ODBC:

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

Installing the MySQL Perl Distribution on Windows

The MySQL Perl distribution contains DBI, DBD:MySQL, and DBD:ODBC.

  • Get the Perl distribution for Windows from http://www.mysql.com/download.html.

  • Unzip the distribution in C: so that you get a C:\PERL directory.

  • Add the directory C:\PERL\BIN to your path.

  • Add the C:\PERL\BIN\MSWIN32-x86-thread or C:\PERL\BIN\MSWIN32-x86 directory to your path.

  • Test that perl works by executing perl -v in a DOS shell.

Problems Using the Perl DBI/DBD Interface

If Perl reports that it can’t find the ../mysql/mysql.so module, the problem is probably that Perl can’t locate the shared library libmysqlclient.so.

You can fix this by any of the following methods:

  • Compile the Msql-Mysql-modules distribution with perl Makefile.PL -static -config rather than perl Makefile.PL.

  • Copy libmysqlclient.so to the directory where your other shared libraries are located (probably /usr/lib or /lib).

  • On Linux you can add the pathname of the directory where libmysqlclient.so is located to the /etc/ld.so.conf file.

  • Add the pathname of the directory where libmysqlclient.so is located to the LD_RUN_PATH environment variable.

If you get the following errors from DBD-mysql, 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 -L/usr/lib/gcc-lib/... -lgcc to the link command when the mysql.so library gets built (check the output from make for mysql.so when you compile the Perl client). The -L option should specify the pathname of the directory where libgcc.a is located on your system.

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

If you get the following error from Msql-Mysql-modules 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.

it means that you need to include the compression library, -lz, to the link line. To do this, make the following change in the file lib/DBD/mysql/Install.pm:

$sysliblist .= " -lm";

to

$sysliblist .= " -lm -lz";

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

If you want to use the Perl module on a system that doesn’t support dynamic linking (like Caldera/SCO) you can generate a static version of Perl that includes DBI and DBD-mysql. The way this works is that you generate a version of Perl with the DBI 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 DBD code linked in, and install that.

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

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

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

shell> perl Makefile.PL -static -config
shell> make
shell> make install
shell> make perl

Then you must install the new Perl. The output of make perl will indicate the exact make command you will need to execute to perform the installation. On Caldera (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 DBD::mysql by running these commands in the directory where your Msql-Mysql-modules distribution is located:

shell> perl Makefile.PL -static -config
shell> make
shell> make install
shell> make perl

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

Get MySQL Reference Manual now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.