Table of Contents
Perl support for MySQL is provided by means of the DBI/DBD client interface. The interface requires Perl Version 5.6.0 or later. It will not work if you have an older version of Perl.
If you want to use transactions with Perl DBI, you need to have DBD::mysql version 1.2216 or newer. Version 2.9003 or newer is recommended.
As of Version 3.22.8, Perl support is no longer included with MySQL distributions. You can obtain the necessary modules from http://search.cpan.org for Unix, or 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 MySQL Benchmarks.
MySQL Perl support requires that you've installed MySQL client programming support (libraries and header files). Most installation methods install the necesssary 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 will 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 CPAN module. For example:
shell> perl -MCPAN -e shell cpan> install DBI cpan> install DBD::mysql
The DBD::mysql installation runs a number of tests. These tests require being able to connect to the local MySQL server as the anonymous user with no password. If you have removed anonymous accounts or assigned them passwords, the tests fail. You can use force install DBD::mysql to ignore the failed tests.
DBI requires the Data::Dumper module. It may already be installed; if not, you should install it before installing DBI.
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:
Unpack the distribution into the current directory:
shell> gunzip < DBI-VERSION.tar.gz | tar xvf -
This command creates a directory named DBI-VERSION.
Change into the top-level directory of the unpacked distribution:
shell> cd DBI-VERSION
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 DBD::mysql 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 DBD::mysql distribution whenever you install a new release of MySQL, particularly if you notice symptoms such as that all your DBI scripts fail after you upgrade MySQL.
If you don't 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.