Installing Database Module for MySQL

This section provides a tutorial example on how to install Perl modules to access MySQL database server with Perl scripts.

Here is what we need to access MySQL database from Perl programs:

For Perl implementation, I have installed ActivePerl on my Windows system. See my other book "Herong's Notes on Perl" for detail information.

To install MySQL server, see my other tutorial book "Herong's Tutorial Notes on SQL".

Perl DBI (Database Interface) module is the basic abstraction layer for working with external database servers. If DBI module is not available on your Perl installation, you can go to and download DBI-1.42.tar.gz. But installing DBI module from the .tar file seems too complicated.

Another easy way to install the DBI module is to use PPM (Perl Package Management) directly from Internet, if you have ActivePerl installed:

herong> \perl\bin\ppm

PPM interactive shell (2.1.5) - type 'help' for available commands.
PPM> install DBI
Install package 'DBI?' (y/N): y
Installing package 'DBI'...
Bytes transferred: 435739
Installing D:\Perl\site\lib\auto\DBI\dbd_xsh.h
Installing D:\Perl\site\lib\auto\DBI\
Installing D:\Perl\html\site\lib\DBI.html
Installing D:\Perl\html\site\lib\Win32\DBIODBC.html
Installing D:\Perl\site\lib\
Installing D:\Perl\site\lib\Win32\
Installing D:\Perl\bin\dbiprof
Installing D:\Perl\bin\dbiprof.bat
Installing D:\Perl\bin\dbiproxy
Installing D:\Perl\bin\dbiproxy.bat
Writing D:\Perl\site\lib\auto\DBI\.packlist
PPM> quit

I don't know how PPM exactly works. My guess is that it comes with a list of modules (packages), not installed, but defined with information about where to go on the Internet to get them and how to install them. Installing additional modules is so easy in this way, as you can see from this example. But I feel that there is a security risk here by allowing PPM to interact with Internet freely without you knowing what it is doing exactly.

The DBD:mysql module is the database driver for MySQL required by the DBI module. It can also be installed by PPM, if you have ActivePerl installed:

herong> \perl\bin\ppm

PPM> install DBD-mysql
Install package 'DBD-mysql?' (y/N): y
Installing package 'DBD-mysql'...
Bytes transferred: 179124
Installing D:\Perl\site\lib\auto\DBD\mysql\
Installing D:\Perl\site\lib\auto\DBD\mysql\mysql.dll
Installing D:\Perl\html\site\lib\Mysql.html
Installing D:\Perl\html\site\lib\DBD\mysql.html
Installing D:\Perl\site\lib\
Installing D:\Perl\site\lib\Mysql\
Writing D:\Perl\site\lib\auto\DBD\mysql\.packlist

But if you want to download the DBI module and install it yourself, you can go to and download DBD-mysql-2.9003.tar.gz.

Table of Contents

 About This Book

 Perl on Linux Systems

 ActivePerl on Windows Systems

 Data Types: Values and Variables

 Expressions, Operations and Simple Statements

 User Defined Subroutines

 Perl Built-in Debugger

 Name Spaces and Perl Module Files

 Symbolic (or Soft) References

 Hard References - Addresses of Memory Objects

 Objects (or References) and Classes (or Packages)

 Typeglob and Importing Identifiers from Other Packages

 String Built-in Functions and Performance

 File Handles and Data Input/Output

 Open Files in Binary Mode

 Open Directories and Read File Names

 File System Functions and Operations

 Image and Picture Processing

 Using DBM Database Files

Using MySQL Database Server

Installing Database Module for MySQL - My First Perl Program with MySQL

 Socket Communication Over the Internet

 XML::Simple Module - XML Parser and Generator

 XML Communication Model

 SOAP::Lite - SOAP Server-Client Communication Module

 Perl Programs as IIS Server CGI Scripts

 CGI (Common Gateway Interface)

 XML-RPC - Remote Procedure Call with XML and HTTP

 RPC::XML - Perl Implementation of XML-RPC

 Integrating Perl with Apache Web Server Module for Building Web Pages

 LWP::UserAgent and Web Site Testing

 Converting Perl Script to Executable Binary

 Managing Perl Engine and Modules on macOS

 Archived Tutorials


 Full Version in PDF/EPUB