It was over four years ago that I first had problems installing the DBD::mysql Perl module on Mac OS X 10.3 Panther. Some things don’t change for the better and I spent most of this afternoon struggling to get up and running DBD::mysql on Mac OS X 10.5 Leopard.
I apparently installed both DBI and DBD::mysql fine but when I tried to access the Movable Type CGIs I was trying to run I’d only see Internal Server Errors and this in the Apache error log:
dyld: lazy symbol binding failed: Symbol not found: _mysql_init Referenced from: /Library/Perl/5.8.8/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle Expected in: dynamic lookup dyld: Symbol not found: _mysql_init Referenced from: /Library/Perl/5.8.8/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle Expected in: dynamic lookup Premature end of script headers: mt.cgi
I did a lot of Googling and found many people with similar problems with “_mysql_init” while trying to get Ruby working, but precious little concerning Perl. The Ruby solutions pointed toward it being something to do with the installed version of MySQL being 64-bit rather than the 32-bit Ruby was expecting. (I know nothing about Ruby, so I’m waving my arms a lot here.)
Because I’d recently moved over from a G4 PowerBook to a new MacBook, using ‘Archive and Install’, my MySQL was initially a PowerPC version. First I’d tried replacing it with the packaged MySQL for “x86_64” because I had a 64-bit machine, but the same errors appeared. So I tried the plain “x86” package, assuming this would be 32-bit. The same errors.
I guessed that maybe when I originally installed DBD::mysql some configuration was set that made it think I still had the PPC version of MySQL installed. So I deleted DBD::mysql:
sudo rm /Library/Perl/5.8.8/darwin-thread-multi-2level/auto/DBD sudo rm /Library/Perl/5.8.8/darwin-thread-multi-2level/DBD
(If you have other DBD::somethings installed you should probably delete …/DBD/mysql rather than the whole …/DBD directories.)
Then I installed DBD::mysql again and, hurrah, mt.cgi finally worked.
You should make sure you have /usr/local/mysql/bin in your $PATH — put this in your ~/.bash_profile:
Then when you install DBD::mysql it picks up the appropriate settings from mysql_config, including setting which version of MySQL you’re using. So make sure you have the correct MySQL installed before installing DBD::mysql. Unlike me.
Thanks to Mike T and Brad Choate for saving my sanity and I hope this saves at least one other person an afternoon of swearing at Google.