[cached copy at OSCR. Original at http://www.lynxafrica.demon.co.uk/dbi]
How to install the Perl module DBI on Linux
About this document
Explanation of DBI and DBD
What this article doesn't do
Please correct my errors
Checking for prerequisites
Explanation of the packages the shell script tests for
Creating data in MySQL
Obtaining DBI and DBD
The purpose of this document is to help with setting up Linux in order to write
a Perl program that gets data from MySQL. Hopefully it will relieve some of
the traffic on the
DBI mailing list.
These instructions cover installing, testing and hopefully understanding more
about the Perl module DBI, and its DBD for MySQL. This document is intended for those that wish to use RPM packages as much as possible.
DBI stands for Data Base Interface. DBI is an add-on, or 'module' for Perl
which gives Perl programs access to databases.
Mysql-DBD is another module, a Data Base Driver for MySQL. DBI uses the
Driver as a
translator to talk to MySQL. So, both modules are required.
This article is about making a working system in the easiest (ie, least secure)
way possible. Use these instructions on a testing or learning only computer
that isn't connected to the Internet.
I am no Linux, Unix, DBI or MySQL guru. These instructions are Red Hat
because that is the Linux I am using. Although this procedure has worked for
me, I can't guarantee it will work on another platform. Also I'm not all that
familiar with compiling Perl modules and programs in general. If you know
better, and you see something wrong with this document, please let me know so I
can fix it.
I assume you are using a recent Red Hat Linux distribution, or a distribution
based on Red Hat which uses the Red Hat Package Manager (RPM) for installing
and verifying programs. You must have root access to the system.
I used a Red Hat Linux 6.0 Intel computer with Apache, Perl and development
tools installed. The way I set this up was to select the Apache server,
development tools and development libraries when installing Red Hat.
The outline of the procedure is:
Here are the basic requirements, as far as I know, for installing Perl DBI and
the DBD for MySQL. This is
an exhaustive list. There may be other required packages which I don't know
Check required packages are installed
Install required packages that are not installed
Obtain Perl DBI and DBD for MySQL
Compile and install Perl DBI and DBD for MySQL
Create a sample database in MySQL
Create a sample table in that database
Create some sample data in that table
Create a MySQL user with access to the sample data
Write a simple Perl program that prints data from MySQL.
For your convenience I have written a
which tests your system to see if you have these packages installed in RPM
format. It only checks to see if the package exists. It doesn't verify the
packages are completely installed, you can do that if you wish.
Run this script, like this:
Perl programming language
A C compiler, eg EGCS
C++ extensions for the C compiler
Glibc development library
MySQL development tools
If all is well, you should get output like this:
If there are no errors in the following list, you should
have everything you need to write a Perl program that gets
data from MySQL.
Checking to see which RPM packages are installed...
The version numbers may vary according to which Linux you are using.
If you see any '...is not installed' messages in the output, you may need to
install that package. Read the next section to learn more about what you may
Many up to date Linux distributions come with all these packages on the
installation media. Others, including Red Hat Linux 6.0, do not supply the
MySQL packages. In this case you can download them in RPM format from
online MySQL documentation.
This explains how to connect to MySQL, create a database, create a table, add
some data to a table, and create a MySQL user with access to that data.
latest DBI module
for Perl from CPAN.
Download it to a safe location, for example, your home directory.
Perl is definitely required.
Make is a standard program used to simplify compiling new programs. DBI and
DBD both use Make as part of the compiling process. You must have this.
Kernel headers are structures and constants needed for compiling most standard
programs. You very likely need this.
EGCS is the C compiler supplied with Red Hat Linux 6.0. The compiler turns
human-readable code into an executable program. If you don't have the EGCS
package installed, perhaps you have another C compiler installed instead. You
don't have to have EGCS, but you do need a C compiler.
EGCS-C++ adds C++ support to the GNU C compiler. I don't
know whether C++ extensions are required but it seems like a good idea to
have it anyway. If you are using another C compiler, this package may be
Glibc contains standard libraries used by multiple programs on the system.
This is one of the base packages in Linux so it is very likely to be installed
on your system. Required.
Glibc-devel contains header files and object files needed when compiling
programs that use the standard C libraries. Required.
MySQL is the database server. Required.
MySQL-client provides a simple, command line interface to MySQL. This is
needed so we can type some data into the database, and to see whether it's been
entered correctly. Required.
MySQL-devel makes it possible for other programs, such as DBI, to work with
Then download the
latest DBD database Driver for MySQL
also from CPAN.
As before, download it to a safe location, like your home directory.
Become root, and enter the following commands:
tar xvzf DBI-1.14.tar.gz
Then read and follow the instructions for compiling DBI.
On perl Makefile.PL: Unable to open MakeMaker.tmp ... permission denied
Meaning: You are not root.
Solution: Become root.
On make test or make install: Lots of error messages like 'can't find stdio.h,
Meaning: The standard C development libraries are not installed.
Solution: Install the glibc-devel RPM package.
Enter the following commands:
tar xvzf Msql-Mysql-modules-1.2214.tar.gz
Then read and follow the instructions for compiling the DBD for MySQL.
Problem: You don't know the answer to the question about where MySQL is
installed on your system. Specifically, it asks for an include directory, but
it's not on your computer.
Meaning: MySQL-devel is not installed.
Solution: Install the MySQL-devel RPM package.
To test your DBI installation, try
Jeffery Baker's DBI Examples.
They are written for Oracle but to make them work with MySQL requires only a
There are other DBI documents at the
DBI main page
including examples specially for MySQL.
I wrote this to help people. Please let me know if it does!
Back to main page