Installing MySQL Database Server for Apple’s Mac OS X Panther

If you want to host a website from your Macintosh running Mac OS X and use some form of Content Management System or Personal Publishing platform, such as Drupal, Mambo, WordPress, etc., then you will need a database for those CMS systems to store their content into. MySQL is free, open source, industrial strength, and one of the most common databases that these CMS systems work with. Let’s compile and install MySQL 4.1.11 for Mac OS X Panther (10.3.x).

While there are binary installers for Mac OS X around, sometimes you want to compile and install directly from the source code, either because you are changing the default build settings, or you want the latest and greatest version before there’s a binary installer. This document will help you through that process.

A MySQL installation requires a Mac OS X user account named mysql. A user account with this name should already exist by default on Mac OS X 10.2 and up so there should be no need for you to create one.

First, download the MySQL source code from one of the mirror sites close to you. Stuffit Expander should, depending on your system configuration, unpack it in it’s download location.

In the Terminal application:

cd path/to/unpacked/folder

(Note: it’s easiest to type ‘cd ‘ [include the space following cd], then drag the unpacked mysql-4.1.11 folder onto the Terminal window, click to select the Terminal window, then press return)

We will set some configuration options to place all of the installed files after compiling them into a new MySQL directory within the Darwin directory hierarchy. We will provide /usr/local/mysql as the location of this new directory and when installed, everything will go there. These are not directories (folders) that you can normally see with the Finder. Also, we need to set a socket that the MySQL server will communicate with other programs through, and we set this as well.

Copy and paste the following 9 lines together into the Terminal and press return.

CFLAGS="-O3" CXX=gcc \
CXXFLAGS="-O3 -felide-constructors -fno-exceptions -fno-rtti" \
./configure \
--prefix=/usr/local/mysql \
--with-unix-socket-path=/usr/local/mysql/sockets/mysql_socket \
--with-mysqld-user=mysql \
--enable-assembler \
--with-comment \

It will take some time to configure, but when complete the downloaded source files are now configured for Darwin, the unix core of Mac OS X and should make a fast, stable binary once compiled.

Lets build it: (this will probably take 10 to 20 minutes, or more)


Now we will install the newly built MySQL database server into the proper places with root permissions:

sudo make install

We will also manually install the initial database tables and populate them.

sudo /usr/local/mysql/bin/mysql_install_db --force

Now we create the directory for the MySQL server’s communication sockets.

sudo mkdir /usr/local/mysql/sockets

And change the group of the installation to the mysql group.

sudo chgrp -R mysql /usr/local/mysql

Finally, set the data and socket directory’s permissions to be owned by the MySQL server so that it can write to them.

sudo chown -R mysql /usr/local/mysql/sockets /usr/local/mysql/var

Starting MySQL is accomplished with:

sudo /usr/local/mysql/bin/mysqld_safe --user=mysql &

This launches the server daemon as a background process in the Terminal. A process ID number should appear, you can just press return to get a Terminal prompt back.

We’re almost done. MySQL 4.1 and up uses an authentication protocol based on a password hashing algorithm that is incompatible with that used by older clients. Since we are installing the 4.1 server, attempts to connect to it with an older client may fail with the following message:

Client does not support authentication protocol requested by server; consider upgrading MySQL client

Specifically, for use with any version of PHP 4 (which we will also be installing), this is a problem that is only fixed by upgrading PHP to version 5 but some CMS systems that you might want to use are not yet PHP 5 compatible. Fortunately, we can still use the older password mechanisms and still use PHP 4. (Any user passwords for databases you create should use the old_password command if you will be using PHP 4, otherwise just use the regular password command)

Secure the installed and running database by adding a password for the two database root user accounts that were created in the installation by using the old_password command. Also, remove the two anonymous accounts as follows:

/usr/local/mysql/bin/mysql -u root
delete from mysql.user where user = '';
set password for 'root'@'localhost' = old_password('thepassword');

Be sure to replace thepassword with a good password of your own choosing. Now we will issue a query on the database to find out what your Macintosh Host name is, in case you don’t know it.

select host,user from mysql.user;

You should see two lines, one with a host of localhost and a username of root. It’s the host name of the other line that we want. Use it in the following command in place of yourhostname as well as a good password of your choosing in place of thepassword. This is also the same Computer Name that is set in Apple Menu>System Preferences>Sharing, only with a .local added on to it.

set password for 'root'@'yourhostname' = old_password('thepassword');

Now we’ll finish up and quit the mysql program.

flush privileges;

Congratulations, you have compiled, installed and secured the powerful MySQL database server. Go get a beverage. The next page of this article will discuss how to set up your Macintosh so that the MySQL server is auto launched at startup.


Comments are closed.