Installing MySQL on Snow Leopard

Just got my new MacPro this weekend. After installing my common applications, I had to install my development tools as well. These are the instructions to install MySQL 64-bit version on OS X Snow Leopard.

First of all, note that we are going to install MySQL compiling from source. So make sure you have installed Xcode tools and you know your way around Terminal 😉

Now lets set up our personal profile where we declare our path variable. Fire up Terminal and create/edit your profile file:

vi ~/.profile

Set your path variable like this:

export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"

Close and save the file. Now load the the path variable to your current shell:

source ~/.profile

Now verify your updated path:

echo $PATH

You should see /usr/local/binat the beginning of the line returned by the system.
Now lets download the MySQL source and start compiling like crazy :

curl -0

tar xzvf mysql-5.1.41.tar.gz
cd mysql-5.1.41
CC=gcc CFLAGS="-arch x86_64 -O3 -fno-omit-frame-pointer" CXX=gcc CXXFLAGS="-arch x86_64 -O3 -fno-omit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" ./configure --prefix=/usr/local/mysql --with-extra-charsets=complex --enable-thread-safe-client --enable-local-infile --enable-shared --with-plugins=myisam,innobase --with-zlib-dir=bundled --with-big-tables --with-readline

sudo make install

cd /usr/local/mysql
sudo ./bin/mysql_install_db --user=mysql
sudo chown -R mysql ./var

Ok, everything should be compiled and installed without problems. Now lets create the launch daemon with the following content

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


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

Change the user to root.

sudo chown root /Library/LaunchDaemons/com.mysql.mysqld.plist

Now, to start / stop MySQL, run the these commands:

sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist
sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysqld.plist

Now the last thing todo is to set the root password:

mysqladmin -u root password "mypassword"

Now MySQL should be running smoothly and without problems on Snow Leopard.
NOTE: For the RoR mysql gem, use the following command:

sudo env ARCHFLAGS="-arch x86_64" gem install mysql -- --with-mysql-dir=/usr/local/mysql --with-mysql-config=/usr/local/mysql/bin/mysql_config