MAMP 1.7 and DBD::mysql

This is a brief post on how to get Perl's DBD::mysql working with MAMP 1.7 on Mac OS X Leopard. The instructions for now, are quite concise.

I have found that using CPAN does not seem to work to install DBD::mysql when you only have MAMP installed. The CPAN commands:

perl -MCPAN -eshell
install DBD::mysql

This I think is due to MAMP not having the correct MySQL files or libraries installed. Below are the steps required to get DBD::mysql working.

Note: You will probably need XCode tools installed to be able to compile the MySQL libraries.

1. Install the header files

Download the full MAMP packages.

The file that you need is called something like MAMP_1.7_intel_full.dmg.

This image contains the required files. Copy:

cp -r /Volumes/MAMP/MAMP/Library/include /Applications/MAMP/Library

2. Install the MySQL client libraries

  1. Download the MAMP sources. MAMP_1.7_src.tar.gz
  2. Untar
  3. Untar the mysql archive file
  4. Change directory to the mysql directory
  5. Configure and build mysql
    ./configure --with-unix-socket-path=/Applications/MAMP/tmp/mysql/mysql.sock \
        --without-server \
    make -j2
  6. Copy libraries
    cp libmysql/.libs/*.dylib /Applications/MAMP/Library/lib/mysql

3. Build and install DBD::mysql

  1. Download DBD-mysql-4.006.tar.gz or similar from CPAN. (Or use the one in ~/.cpan/build/DBD-mysql-4.006)
  2. Build
    perl Makefile.PL --CFLAGS="-I/Applications/MAMP/Library/include/mysql -Os -arch i386 -fno-common" \
        --libs="-L/Applications/MAMP/Library/lib/mysql -lmysqlclient -lz -lm" \
    make test
    sudo make install

Make test may throws errors about connecting to the database server but should not throw an errors about using shared libraries or missing symbols.