The Perl DBI module provides a generic
interface for database access. You can write a DBI script that
works with many different database engines without change. To use
DBI, you must install the DBI module, as well
as a DataBase Driver (DBD) module for each type of server you want
to access. For MySQL, this driver is the
DBD::mysql module.
Perl DBI is the recommended Perl interface. It replaces an older
interface called mysqlperl, which should be
considered obsolete.
Installation instructions for Perl DBI support are given in Section 2.4.20, “Perl Installation Notes”.
DBI information is available at the command line, online, or in printed form:
Once you have the DBI and
DBD::mysql modules installed, you can get
information about them at the command line with the
perldoc command:
shell>perldoc DBIshell>perldoc DBI::FAQshell>perldoc DBD::mysql
You can also use pod2man,
pod2html, and so forth to translate this
information into other formats.
For online information about Perl DBI, visit the DBI Web site,
http://dbi.perl.org/. That site hosts a general
DBI mailing list. MySQL AB hosts a list specifically about
DBD::mysql; see
Section 1.7.1, “MySQL Mailing Lists”.
For printed information, the official DBI book is Programming the Perl DBI (Alligator Descartes and Tim Bunce, O'Reilly & Associates, 2000). Information about the book is available at the DBI Web site, http://dbi.perl.org/.
For information that focuses specifically on using DBI with MySQL, see MySQL and Perl for the Web (Paul DuBois, New Riders, 2001). This book's Web site is http://www.kitebird.com/mysql-perl/.

User Comments
When using the DBI/DBD Perl interface routines along with mysql_multi(aka a socket file different from mysql.sock) you should set the perl env variable MYSQL_UNIX_PORT as referenced in your mysql.cnf file. Example:
$ENV{MYSQL_UNIX_PORT} = "/tmp/mysql.sock2";
To clarify what Elliot said, there is a new location for the socket connection to MySQL with the new MySQL database version 5. If you are using the newer version of MySQL you need to update your perl scripts to reflect the new location of the MySQL socket.
Your older perl script might give you a warning like this:
DBI connect('sometable','somename',...) failed: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) at ./mysql_manip.pl line . . .
Which might mean that the perl program cannot find the socket since the socket has moved. Tell your perl script where the new socket is by looking for it in /tmp and insert that information as a variable in your perl script.
The socket path can also be set using "mysql_socket=" in the $dbh->connect() method.
A DBD::mysqlPP driver exists which requires no compilation and no mysql libraries or source code.
http://search.cpan.org/~oyama/DBD-mysqlPP-0.04/
Add your own comment.