Perl Tutorials - Herong's Tutorial Examples - Version 5.32, by Dr. Herong Yang
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 http://search.cpan.org/dist/DBI/ 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:
\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\DBI.bs ...... Installing D:\Perl\html\site\lib\DBI.html Installing D:\Perl\html\site\lib\Win32\DBIODBC.html ...... Installing D:\Perl\site\lib\DBI.pm Installing D:\Perl\site\lib\Win32\DBIODBC.pm ...... 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 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:
\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\mysql.bs 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\Mysql.pm Installing D:\Perl\site\lib\Mysql\Statement.pm ...... 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 http://www.mysql.com and download DBD-mysql-2.9003.tar.gz.
Table of Contents