Installing MySQL and MySQL gem (Not Updated)

On Mac OSX (Snow Leopard)

Prerequisites

  • Xcode Tools (latest available directly from Apple)

Download the source (And installation)

We will need to download mysql sources (the generic linux/unix tarball) this link may change in the future but currently it works.

If the link doesn't work just go to mysql downloads page and in the Platform select box make sure you select "Source Code". Then select the "Architecture independent - Generic linux" version from the bottom.

Download and Install it [1]:

mkdir ~/Sources
cd ~/Sources
curl -O http://mirror.services.wisc.edu/mysql/Downloads/MySQL-5.1/mysql-5.1.50.tar.gz
tar xvvf mysql-5.1.50.tar.gz && cd mysql-5.1.50
./configure --prefix=/usr/local/mysql --with-extra-charsets=complex --enable-thread-safe-client --enable-local-infile --enable-shared --with-plugins=innobase
make
sudo make install

We now need to setup the mysql database:

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

We should now include mysql bin folder in our $PATH if it's not included yet. First lets check:

$> echo $PATH
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

If the result doesn't show "/usr/local/mysql/bin" then we need to manually include it:

echo "export PATH=$PATH:/usr/local/mysql/bin" >> ~/.profile && . ~/.profile

Now, that line is ugly and it's intended only for lazy people, but it basically appends the "export PATH=$PATH:/usr/local/mysql/bin" to the end of the ~/.profile file. You can do it manually using your favorite editor, and you should check if the variable is already defined, then just modify that line.

Starting automatically on boot

Create a new file and name it "com.mysql.mysqld.plist", then put this contents in it:

<?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>

And move it to the /Library/LaunchDaemons folder and chown it to root, or skip all this and just run this code:
echo "<?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>" >> ~/com.mysql.mysqld.plist
sudo mv ~/com.mysql.mysqld.plist /Library/LaunchDaemons/com.mysql.mysqld.plist
sudo chown root /Library/LaunchDaemons/com.mysql.mysqld.plist
sudo launchctl load -w /Library/LaunchDaemons/com.mysql.mysqld.plist

You should now have successfully installed mysql. Try it out:

mysql -uroot

Installing the gem

You might get some "collation" or something problems if you install it as a regular gem, therefore install it as follows:

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

There shouldn't be any other gem to which you would need to specify ARCHFLAGS env variable for.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License