Installing DBD::MySQL on Mac OS X El Capitan

El Capitan

Every time I upgrade OS X, this issue comes up. I cannot get Perl to work with MySQL, because the Perl module DBD::MySQL fails to install properly. The reason this happens is because one required dependency, libmysqlclient.18.dylib, could not be located by the install script. Hence the error message “Library not loaded: libmysqlclient.18.dylib”. This is how you fix the problem.

  1. Install MySQL on your Mac
  2. Start the MySQL server
  3. Open the Terminal and navigate to /usr/lib
    cd /usr/lib
  4. Enter the command (see below if you can’t):
    sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
  5. Use CPAN (sudo cpan) to install DBI 
    sudo cpan
    install DBI
  6. Use CPAN to install DBD::MySQL 
    install DBD::MySQL

There you go. Your nightmare is over. The installation should work, and now you can use Perl with MySQL!

What to do when you are not able to sudo ln

If OS X would not let you enter the sudo ln command, it’s probably because of OS X’s System Integrity Protection, which is a total pain for LAMP developers who use OS X. This can be disabled with these steps:

  1. Turn off your computer
  2. Turn on your computer while holding down the Command + R keys
  3. Once recovery mode is booted, launch Terminal
  4. Disable System Integrity Protection with:
    csrutil disable
  5. Reboot your computer

WARNING: you should only do this if you fully understand what you are doing and fully understand the consequences of your actions.