Being new to the OS/X world but not unix i want to prepare myself for this installation since i want to build and install from source than from pre-built package. This because i want absolute control on the version of MySQL which i intend to use in many different projects and i don’t want any stupid auto-update mechanisms to screw this up. Having said that it seems to be a fairly easy process still.
Background
I used the following two for reference. So spend time reading it to get a better understanding on steps involved before proceeding. I was successful by combining approach from both the two.
1. http://www.malisphoto.com/tips/mysql-on-os-x.html#Anchor-Download
2. http://hivelogic.com/articles/compiling-mysql-on-snow-leopard/
Pre-installation.
1. First check that your Snow Leopard has the user and group for the mysql. Use the command “dscl . list /users” and “dscl .list /groups” for this. You should see _mysql user and group.
2. I plan to install the mysql under the /usr/local directory. Wondering why? Read this article.
3. Ensure that you’ve XCode installed. If you recently upgraded from Leopard to Snow Leopard make sure that you run XCode install on the CD before you proceed. Remember we need to build from the source and it is possible only with the tools from XCode.
Installation
1. Download the source in tar format from here.
2. It is a best practice to control the unix socket file for mysql and it is preferred to be in /var directory. So create and set permission for socket dir.
cd /var
sudo mkdir _mysql
sudo chgrp mysql _mysql
sudo chmod 775 _mysql
3. Create src directory under /usr/local/ directory.
mkdir /usr/local/src/
4. cd to the src directory
cd /usr/local/src
5. Extract the source tar downloaded in step 1. Here the assumption tar file is in your downloads folder.
tar xzvf ~/Downloads/mysql-x.x.xx.tar.gz
6. cd to the extracted source. x below = version you downloaded
cd mysql-x.x.xx dir
7. This is a very important step in configuring the build of mysql. Please pay attention to each options used here. Look here to know more about each configuration option before using it.
./configure --prefix=/usr/local/mysql
--with-extra-charsets=complex
--enable-thread-safe-client
--enable-local-infile
--enable-shared
--with-plugins=innobase
--with-mysqld-user=_mysql
--with-unix-socket-path=/var/mysql/mysql.sock
8. Now it’s time to build
make
9. Now it’s time to install
sudo make install
10. Now that mysql is installed we need the server to be up and running once the system is started. Easy and the standard way to do this OS/X is launchd. Create a file named com.mysql.mysqld.plist under /Library/LaunchDaemons with below content with sudo account permission. Make sure to check path/s.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.mysql.mysqld</string>
<key>Program</key>
<string>/usr/local/mysql/bin/mysqld_safe</string>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string>mysql</string>
<key>WorkingDirectory</key>
<string>/usr/local/mysql</string>
</dict>
</plist>
11. Next step is to use the launchd to start mysql.
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist
12. If you did not see anything after last command then it is good. Now login to mysql.You should now see the mysql command interpreter.
mysql -u root
13. I don’t really need my MySql to be secured at this point for dev environment. If you do then please take a look at this.
Finally
Stopping MySql
sudo launchctl unload -w /Library/LaunchDaemons/com.mysql.mysqld.plist
Starting MySql
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist