Category Archives: MySQL

Setting MySQL to Load on Startup (Mac OS X 10.10)

It used to be that you could easily set up MySQL to load at startup using a MySQL plugin on system preferences. Unfortunately, Apple killed support for this in recent versions of OS X. So, you must set this up using a more Unix-like setting with launch daemon (launchd).

Here are the instructions for setting that up.

First, create a plist file at the following location. I’m using the vi editor because it’s easy.

sudo vi /Library/LaunchDaemons/com.mysql.mysqld.plist

Then fill it with the following XML.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">

Then an adjust the permission:

sudo chown root /Library/LaunchDaemons/com.mysql.mysqld.plist
sudo chgrp wheel /Library/LaunchDaemons/com.mysql.mysqld.plist
sudo chmod 644 /Library/LaunchDaemons/com.mysql.mysqld.plist

MySQL Time Zone on OS X Mavericks

Setting up the time zone table on your MySQL instance on OS X shouldn’t be this hard, but it is. Normally, you do this with the following simple command and you’re done, but not on OS X.

mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p mysql

The first problem you’ll encounter is that mysql_tzinfo_to_sql is not accessible from the command line. You either have to walk the path to its location and prepend the command with a dot or you have to reference the full path before the command (sans the dot).

The second problem you’ll encounter is that there are multiple errors in the time zone files, which will prevent the data from loading. I found a few options for dealing with this, but the easiest — by far — was to tell MySQL to force-load the files that worked and skip those that didn’t.

Here is the working command on my Mac.

/usr/local/mysql/bin/mysql_tzinfo_to_sql /usr/share/zoneinfo | mysql -u root -p --force mysql

MySQL & Perl on OS X Mavericks

After upgrading to Mavericks, my local development environment stopped working — more specifically, Perl would no longer talk to MySQL.

Recently, I decided to figure it out.

I was getting the following error from a Perl script that was trying to talk to my database. The database was there, it was accessible from the command line, and I verified that my Perl DBI libraries were installed.

install_driver(mysql) failed: Can't load '/Library/Perl/5.16/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle' for module DBD::mysql: dlopen(/Library/Perl/5.16/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle, 1): Library not loaded: libmysqlclient.18.dylib
  Referenced from: /Library/Perl/5.16/darwin-thread-multi-2level/auto/DBD/mysql/mysql.bundle
  Reason: image not found at /System/Library/Perl/5.16/darwin-thread-multi-2level/ line 194.
 at (eval 21) line 3.

After some searching, I realized that Perl was trying to load MySQL, but from the wrong location. Perl expected the libmysqlclient.dylib to live at /usr/lib but Mavericks had installed it at /usr/local.

So, I created a symlink to redirect Perl to the right location.

sudo ln -s /usr/local/mysql-5.6.17-osx10.7-x86_64/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib

It should be noted that libmysqlclient.dylib will contain version information in the filename and Perl will expect it there. Your version is likely different than mine, so be sure to update it as needed. If you’re wondering, what version Perl is looking for, read your error message and that will tell you.