Perl MySQL DBD Interface

It is quite common to develop applications that use the Perl MySQL DBD interface (e.g. a Web UI to your data). If this is your plan, you will need some extra Perl modules so you might as well fire up CPAN and get started with their installation. In order to do this, make sure that the server has access to the outside world (through your firewall) so it can download the Perl modules from the selected CPAN site. Once it does, type:

     su
     perl -MCPAN -e shell

The first time through, you can let automatic configuration set everything up. All that remains is to set up the URL list, which you do with:

CPAN will then ask you to pick some mirror sites for downloading sources. Apparently, those sites that use FTP are typically slow and prone to fail so you may wish to only consider those sites that use HTTP. If you pick North America and United States, here are the sites that we use:

     http://cpan.belfry.net/
     http://cpan.mirror.facebook.net/
     http://mirrors.ibiblio.org/CPAN/
     http://www.perl.com/CPAN/

If you ever need to redo the list of sites, you can rerun the configuration at any time from the command line with:

Once you have made your choices, remember to commit the configuration with:

There is more information at:

     http://rackerhacker.com/2008/06/16/adjusting-cpan-mirror-list/

Here are a list of modules that we install before we install the MySQL DBD interface:

     install Bundle::CPAN
     force install Date::Calc  (later versions have it already)
     install Time::HiRes

If the install of Time::HiRes fails, exit CPAN, do the following and then rerun the install of HiRes from scratch:

     export LC_ALL=C

If you care that the install gets to run all of its built-in tests, to verify that the install worked OK, before installing the MySQL bundle you will need to exit CPAN set the environment variables needed by the Perl install script:

     export DBD_MYSQL_TESTDB=stores
     export DBD_MYSQL_TESTUSER=root
     export DBD_MYSQL_TESTPASSWORD=itsasecret  (use the actual root password)
     export DBD_MYSQL_TESTHOST=localhost
     export DBD_MYSQL_TESTPORT=3306

Note that the super user password is now stored in an environment variable in plain text. This is a big security hole. Only do this for the time needed to run the Perl install script.

Create a database that can be used by the install script. To do so, run mysql and do the following:

     mysql -uroot -p
       rootsecretpassword
       create database stores;
       quit

After exiting from mysql, restart CPAN and then install DBD:

     perl -MCPAN -e shell
     install Bundle::DBD::mysql

We're now done with the Perl test database so we can get rid of it:

     mysql -uroot -p
       rootsecretpassword
       drop database stores;
       quit

At this point, you must log off to clear the environment variables with the super user password in them. Then, you need to edit root's bash history to delete the line where you set the password. To do that, log on as root again. With your favorite editor, edit /root/.bash_history and remove any lines that contain the root password. Save the file. Log out again (the command that sets the password is still in the in-memory command history). You can log in for a third time and check that the plaintext password is no longer visible in the command history. What a pain in the butt! Nice install procedure.

Incidentally, if you wish, you can skip all of the steps to create a test database and just install the MySQL DBD Interface without it. All of the install script's test steps will be skipped and the install will complete successfully. Most of the time, this is all that it takes. Its a lot simpler.

Oh, and while we're talking about incidentals, you can often install this module directly with your Operating System's package manager. If this option is available, you should probably take it.