In order to successfully connect to a MySQL database with Perl, you will first need to ensure that the MySQL drivers are installed on your system. This tutorial is all about the standard Perl DBI (DataBase Interface) and DBD:MySQL (DataBase Driver for MySQL). If you're working on a web server or hosting service that allows you to utilize both Perl and MySQL, chances are the Perl DBI is already installed. Try jumping to the creating a simple database step, or the connecting to the MySQL database step.
If you are developing on your windows machine using ActiveState's ActivePerl you will need to install the Perl DBI and DBD:MySQL yourself. This can be done in a few quick steps using the installed Perl Package Manager.
Before you start, make sure you have a workable connection to the internet. The Perl Package Manager will need the connection to connect to CPAN and download the modules.
First, we need to start the Perl Package Manager. Click on your start menu and select the Run... option. In the pop-up window, type cmd and hit enter. This will bring up the Windows command line. If you did the default install of ActiveState's ActivePerl, you should be able to type ppm at the prompt to start the Perl Package Manager. You should see a new prompt like so:
Next we will need to install two Perl modules from CPAN - luckily this couldn't be simpler. First comes the DBI (DataBase Interface) which can be installed by typing install DBI at the ppm> prompt. You'll see several lines of installation scroll by, just wait until it completes.
Entering interactive shell. Using Term::ReadLine::Perl as readline library. Type 'help' to get started. ppm>
Finally we install the MySQL driver for the DBI. This is done by typing install DBD-mysql at the ppm> prompt. Once again, you'll see several lines of installation text scroll by. When it's done, you'll be ready to move on to creating a simple database.