CHANEY LAW FIRM BLOG

Subscribe to our Blog

Perl, MySQL, and Mac OS X

I use MySQL, Perl, and PHP running on Mac OS X for various projects. When I install an operating system update, the Perl/MySQL link invariably breaks, as the packages necessary to connect the two aren’t installed on Mac OS X by default. Instead of googling the fix every time I update, I figured I’d post it here for future reference.

  1. Download and install XCode from Apple’s website (v.3.2.6) or the App Store.

  2. Download the header files for the built-in version of MySQL from Apple’s website (here’s a link to the support article for 10.6 Server). Note that this is installed using the command-line tool tar, rather than double-clicking the archive file you download.

  3. Run CPAN to install DBI and its dependencies by executing the command sudo perl -MCPAN -e ‘install DBI’ .

  4. Download a version of DBD::mysql and expand it to a source directory somewhere (such as ~/src/).

  5. Open the MySQL Support page “2.4.5. Using the Bundled MySQL on Mac OS X Server”, which identifies the locations of files in the bundled MySQL version that comes with Mac OS X Server.

  6. Execute perl Makefile.PL from the source directory mentioned above without any flags, which will give you the default settings. This will error out because the MySQL header file locations are wrong (this is why I haven’t been able to figure out how to use CPAN to install DBD::mysql).

  7. Execute perl Makefile.PL again, this time substituting the header file locations on the MySQL page referenced above for the —cflags, —lib, and —testsocket flags. Remember to copy the remaining system-dependent defaults for the —cflags and —lib flags. You may need to change other flags as well, depending on your installation. (For instance, on Mac OS X 10.6 server, the command I used was: perl Makefile.PL —cflags ‘-I/usr/include/mysql -fno-omit-frame-pointer    -pipe   -D_P1003_1B_VISIBLE -DSIGNAL_WITH_VIO_CLOSE -DSIGNALS_DONT_BREAK_READ -DIGNORE_SIGHUP_SIGQUIT’ —libs=’-L/usr/lib/mysql -lmysqlclient -lz -lm’ —testuser=test —testsocket=’/var/mysql/mysql.sock’ “).

  8. Execute make, make test, and sudo make install as you normally would.

This should get MySQL and Perl talking to each other using the bundled Mac OS X MySQL package.