Sunday, August 3, 2008

Macbook - Macports MySql server complete install HowTo

Some time ago I setup MySql on my macbook using macports and the comments I got about this post included some useful information to automate starting MySql on startup.

Here is the complete process to get mysql server working (mysql5 in my case):
# install server and the launch script
# needed to start it. (I like the -v option
# to see what is happening.)
$ sudo port -v install mysql5 +server

# initialize the setup as mysql user.
$ sudo -u mysql mysql_install_db5

# start mysql and set your root password.
$ sudo -u mysql /opt/local/lib/mysql5/bin/mysqld_safe &
$ sudo /opt/local/lib/mysql5/bin/mysqladmin -u root password '[new_passwd]'

Now it would be nice if this all started on bootup instead of the last command above. Here are the steps to include it in the automated launchd configuration:
# Create the launchd directory.
$ sudo mkdir -p /Library/StartupItems/LaunchDaemons

# Now create a launch plist file:
$ sudo vim /Library/StartupItems/LaunchDaemons/org.mysql.launchd.mysql.plist

# Here is the XML you need to put into the plist file:

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

# Finally, need to load this into launchd or you can just
# reboot to have it picked up automatically.
$ sudo launchctl

launchd% load /System/Library/LaunchDaemons/org.mysql.launchd.mysql.plist
launchd% exit

I would also like to point to VelociPeek where Eric (another software man in the Eric club!) details more in this area.