# Compling MySQL for Mac OS X client



## BjarneDM (Nov 4, 2005)

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:

```
mkdir -p ~/WebServer/MySQL
cd ~/WebServer/MySQL
```
In the above folder save the following as 'mysql.bash' :

```
#!/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'):

```
sudo mkdir -p /Library/StartupItems/MySQL
```
In the above folder save the following as just 'MySQL'

```
#!/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'

```
{
  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':

```
MYSQL=-YES-
```


----------



## BjarneDM (Nov 17, 2005)

Forgot to write, that you'll need to have installed DarwinPorts as described here: http://www.macosx.com/forums/showthread.php?p=1245233#post1245233 or modify the paths and replace 'darwinports' with 'usr' where appropriate.


----------



## ElDiabloConCaca (Nov 17, 2005)

Very nice step-by-step!  Thanks!


----------



## BjarneDM (Nov 20, 2005)

If it's a first-time install, you'll have to follow the instructions given here: http://dev.mysql.com/doc/refman/5.0/en/unix-post-installation.html - suitably modified of course.

Also, if you want to be able to just run the MySQL commands without first cd'ing to the MySQL bin directory, you'll have to modify your PATH environment variable:

```
export PATH=/Library/MySQL/bin:${PATH}
```


----------

