I ran my own blog from November 2006 till October 2014. All posts are still online, but I don't have time to update it anymore. Please note that all images and media files have been removed when the backup was moved to a new host in early 2016. Enjoy!

Snow Leopard - Install MySQL and Perl DBI/DBD

13. september 2009

I just installed Snow Leopard on my MacBook Pro and it runs just fine. Unfortunately some people seem to have problems to get MySQL and/or Perl DBI working on MacOS X, so here's a little post that my help.

One of the big advantages of MacOS X 10.6 is the fact that a lot of disk space is being freed up. Snow Leopard achieves this by removing lots of things from your disk, but in some cases this may also affect some UNIX software you've manually installed on your machine. So don't forget to backup all the weird stuff you've installed on your machine!

So here's what to do if you wish to use MySQL along with Perl on your Snow Leopard workstation or server:

First you'll have to download MySQL from www.mysql.com. I've opted for the 64 bit x86 disk image. You'll have to create an account on the MySQL site if you don't have one yet.

The downloaded image contains three components: the MySQL installer, the startup item installer (both MacOS X packages) and the preferences pane. Install the database engine and the startup item by double clicking the packages and by following the onscreen instructions.

Move the preference pane to /Library/PreferencePanes. This will allow to start/stop the MySQL engine using the MacOS X preferences app later on.

For some obscure reason you won't be able to start MySQL after installing it, as some access rights are not being correctly applied during the installation process.

To solve this problem, open a terminal and type the following:

cd /usr/local/mysql

Now change the access rights to the data directory so that you can read and write this directory. For example:

chown -R mysql data

I'd also recommend to add a .profile file in your MacOS X home directory (/Users/YourName/.profile) which should contain the following line:

export PATH="$PATH:/usr/local/mysql/bin"

This will allow to use the commands in /usr/local/mysql/bin in your terminal, no matter what your current working path is.

Use the MySQL preference pane in the MacOS X preferences to start the MySQL database, or type the following in your terminal:

mysql start

If the engine doesn't start up, check the permissions of /usr/local/mysql/data once again and fix them if required.

As soon as the MySQL engine is running, change the mysql root password using mysqladmin:

mysqladmin -u root password "somepassword"

Now you can create your databases, tables and everything else.

To access the MySQL database from your Perl scripts you'll have to install Perl DBI. Snow Leopard upgrades Perl from 5.8 to 5.10, and deletes everything related to Perl 5.8 - if you had DBI/DBD installed then the MacOS X updater will now have removed it.

Install (or reinstall) DBI using the following command in your terminal:

sudo cpan DBD::mysql

For some obscure reason cpan didn't manage to install DBI on my laptop. In this case you'll have to install it manually. Open the following URL in your web browser:


Search for "DBD::mysql" and download the latest package. The zipped package should be saved in your Downloads folder. Open it if it hasn't been unpacked automatically.

Use your terminal and move inside the DBD::mysql directory. Then type the following commands:

perl ./Makefile.PL


sudo make install

If you're lucky you won't get any serious errors (warnings are okay), which means that both MySQL and Perl DBI/DBD have been successfully installed.

Okay, hope this helps - have fun with Perl and MySQL!!!