Installing DBD::MySQL on Mac OS X 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.
- Install MySQL on your Mac
- Start the MySQL server
- Open the Terminal and navigate to /usr/lib
cd /usr/lib
- Enter the command (see below if you can’t):
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
- Use CPAN (sudo cpan) to install DBI
sudo cpan
install DBI
- 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:
- Turn off your computer
- Turn on your computer while holding down the Command + R keys
- Once recovery mode is booted, launch Terminal
- Disable System Integrity Protection with:
csrutil disable
- 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.