Compling MySQL for Mac OS X client

BjarneDM

Registered
The version of MySQL you can get from the MySQL homepage doesn't seem to have the shared libraries needed to enable PHP to connect to MySQL. Thus, we'll have to compile MySQL ourselves.

Create and enter the folder we'll use to compile from:
Code:
mkdir -p ~/WebServer/MySQL
cd ~/WebServer/MySQL
In the above folder save the following as 'mysql.bash' :
Code:
#!/bin/bash

if [ ! -e mysql-${1}.tar.gz ]
then
    curl -O --url ftp://sunsite.dk/mirrors/mysql/Downloads/MySQL-${1%\.*}/mysql-${1}.tar.gz \
         --disable-epsv --disable-eprt
fi

rm -rf mysql-${1}
tar -zxf mysql-${1}.tar.gz

cd mysql-${1}

export PATH=/Developer/Tools:/bin:/sbin:/usr/bin:/usr/local/bin:/usr/sbin

# http://dev.mysql.com/doc/mysql/en/Mac_OS_X_10.x.html
export CC="gcc"
export CFLAGS="-O3 -fno-omit-frame-pointer"
export CXX="gcc"
export CXXFLAGS="-O3 -fno-omit-frame-pointer -felide-constructors -fno-exceptions -fno-rtti" 
./configure \
    --prefix=/Library/MySQL \
    --exec-prefix=/Library/MySQL \
    --with-extra-charsets=complex \
    --enable-thread-safe-client \
    --enable-local-infile \
    --with-openssl \
    --with-openssl-includes=/darwinports/include \
    --with-openssl-libs=/darwinports/lib \
    --with-zlib=/darwinports \
    --enable-shared \
    --enable-static

make

sudo apachectl stop
sudo SystemStarter stop MySQL

sudo rm -rf /Library/MySQL/lib /Library/MySQL/include
sudo make install

sudo SystemStarter start MySQL
sudo apachectl start

export PATH=/Library/MySQL/bin:${PATH}
mysql --version
Make the file executable: chmod o+x mysql.bash
Then just execute the following command : ./mysql.bash 5.0.15

We'll also need a MySQL StartupItem (remember to make it executable with 'chmod o+x MySQL'):
Code:
sudo mkdir -p /Library/StartupItems/MySQL
In the above folder save the following as just 'MySQL'
Code:
#!/bin/sh

##
# MySQL Server
##

. /etc/rc.common

StartService ()
{
    if [ "${MYSQL:=-NO-}" = "-YES-" ]; then
        ConsoleMessage "Starting MySQL Server"
        cd /Library/MySQL
        ./bin/mysqld_safe &
    fi
}

StopService ()
{
    ConsoleMessage "Stopping MySQL Server"

    PIDS=`ps ax | grep mysql | grep -v grep | awk '{print $1}'`

    for pid in $PIDS; do
        kill -KILL $pid
    done
}

RestartService ()
{
    StopService
    sleep 3
    StartService
}

RunService "$1"
and the follwing as 'StartupParameters.plist'
Code:
{
  Description     = "MySQL Server";
  Provides        = ("MySQL");
  Requires        = ("Resolver");
  OrderPreference = "Late";
  Messages =
  {
    start = "Starting MySQL Server";
    stop  = "Stopping MySQL Server";
  };
}
Then append the following line to '/etc/hostconfig':
Code:
MYSQL=-YES-
 
Back
Top