Compiling and Installing MariaDB 5 on Mac OS X Mavericks

May 20, 2020



MariaDB 5.3 is an enhanced drop-in replacement for MySQL 5.1.

This document assumes that the OS X command line developer tools (XCode 6.0.1) are installed, that you are logged in as an administrator, and using the BASH shell. These instructions can also be used on OS X (Mountain) Lion.

These instructions also assume that you are installing MariaDB from scratch for the first time. If in the past, you have installed MariaDB from source, you may not have to perform some of the steps such as creating the MariaDB source or socket directories.

I have tried to make this document as concise and direct to the point as possible. It is helpful to have some knowledge of the basic UNIX commands and permissions, and the GNU build system.

Download the source code and unpack into source directory

Download the MariaDB source code

Download the MariaDB Generally Available Release (GA) source code from Select Download Maria5.3 Stable and download the Source tar.gz file (mariadb-5.3.12.tar.gz).

Create the source code directory and unpack

Launch Terminal and execute the following commands where adminID is your administrator ID. Your administrator ID is the name you used to login to OS X with administrator privileges. OS X refers to this name as a short name. Under UNIX this name is called your user name or login name. Execute the whoami command to find out your user name.

# Create a /usr/local/src directory if it doesn't already exist
cd /usr/local
sudo mkdir src
sudo chown adminID src
sudo chgrp admin src
chmod 750 src

# Change to the source directory and unpack (Substitute appropriate version number)
cd src
tar -xvzf ~/Downloads/mariadb-5.3.12.tar.gz

# If Safari has already attempted to open the archive after downloading it, you may have to do this instead
tar -xvf ~/Downloads/mariadb-5.3.12.tar

# Consider changing the owner or group of the /usr/local directory to your admin id or the admin group. It will make administration easier as you don't have to do so many sudo's or run as root.

# Some of the commands used in this document require the BASH shell. All versions of OS X from version 10.3 on up default to using BASH. However, if you upgraded OS X from an earlier version and imported your home directory, you may still be running TCSH. To find out what default login shell you are running and change it, go to the System Preferences Accounts pane. If the pane is locked, unlock it. Control Click on your account name and a contextual menu will appear. Click on Advanced Options. You will then be presented with a dialog where you can change the default login shell to whatever you want. You can also use the dscl utility to read and change the default login shell. Execute the following to read the directory service properties of your id:
dscl . read /Users/YourID.

# To find out what YourID is, execute the whoami command.

Create the MariaDB Socket Directory

# Create and set permissions for /var/mysql directory
cd /var
sudo mkdir mysql
sudo chgrp mysql mysql
sudo chmod 775 mysql

Build, Test and Configure MariaDB

You may want to build MariaDB with different options, such as a another default charset and collation.
Use the ./configure --help command to get a complete list of build time options.

Execute the following commands in Terminal:

The OS X command line developer tools must be installed.

# Change to the source directory (Substitute appropriate version number)
cd /usr/local/src/mariadb-5.3.12

# Configure the make file for the architecture you are compiling on (64-bit x86 Binary for Mavericks)
./configure \
--prefix=/usr/local/mariadb-5.3.12 \
--with-unix-socket-path=/var/mysql/mysql.sock \
--with-mysqld-user=_mysql \
--enable-assembler \
--with-extra-charsets=complex \
--enable-thread-safe-client \
--with-big-tables \
--with-aria-tmp-tables \
--with-plugin-xtradb \
--without-plugin-innodb_plugin \
--with-plugins=max-no-ndb \
--with-mysqld-ldflags=-static \
--with-client-ldflags=-static \
--with-readline \
--with-ssl \
--with-embedded-server \
--with-libevent \
--with-zlib-dir=bundled \

# Patches required on OS X Mavericks
# Delete any line that starts with #include from the following API cannon pp files:
# include/mysql/client_plugin.h.pp
# include/mysql/plugin_auth.h.pp
# include/mysql.h.pp
# Strip the includes
sed -i .bak '/^#include/ d' include/*.h.pp include/mysql/*.h.pp

# Build the executables

# Test the build
cd mysql-test
perl --force /* Run without stopping for errors

# Keep in mind that if you do get an error when testing, it will often be caused by a bug in the test itself, or an isolated bug that doesn't affect most applications.

# Copy the installation to the default /usr/local/mariadb-5.3.12 directory
cd ..
sudo make install

# Copy the configuration file to /etc
sudo cp support-files/my-medium.cnf /etc/my.cnf
cd /etc
sudo chown <adminID> my.cnf
sudo chgrp mysql my.cnf
chmod 640 my.cnf

# Create a symbolic link to the mariadb binary installation directory
cd /usr/local
sudo ln -sfhv /usr/local/mariadb-5.3.12 /usr/local/mysql

# Configure MariaDB installation directory permissions
# If you overwrote your existing installation, don't perform this step,
# as the recursive chown's will change the permissions on your database directory to something other than mysql.
sudo chown -RH <adminID> mysql
sudo chgrp -RH admin mysql
sudo chgrp _mysql mysql
sudo chmod 775 mysql
sudo chmod -h 775 mysql
sudo chgrp -h admin mysql
sudo chown -h <adminID> mysql

# Create the database directory and initialize the grant tables
cd mysql
sudo bin/mysql_install_db --user=_mysql

# Note: If you are running MariaDB 5.3 and receive the error - [ERROR] /usr/local/mysql/libexec/mysqld: unknown option '--skip-federated', you may have an old /etc/my.cnf configuration file. Edit my.cnf and delete or comment out the skip-federated option.

# You may also want to add the lower_case_table_names = 2 option to /etc/my.cnf to keep the server from generating warnings in the log file about lower case table names. Add this option under [mysqld].

Start the MariaDB database server and check for errors and warnings

Use the MariaDB utility mysqld_safe to start the server

Execute the following commands in Terminal:

# Start the server - Make sure to stop any MariaDB servers already running
cd /usr/local/mysql
sudo -b bin/mysqld_safe

# Check for startup errors and warnings
# Change to user root
sudo -s

# Change to the database directory
cd var

# List the directory

# Dump the error log
cat <ComputerName>.err

# Exit from user root

# To stop the server ...
cd ..
bin/mysqladmin -u root -p shutdown

Add MariaDB Utilities Directory to the shell path

Use your favorite editor to edit the bash shell .bash_profile configuratiion file in your home directory.

Execute the following commands in Terminal:

# Change to the home directory

# Create .bash_profile if it doesn't exist
touch .bash_profile

# Edit the shell startup script with your favorite editor
nano .bash_profile

# Add the MariaDB directory to the path and exit the editor
export PATH=$PATH:/usr/local/mysql/bin

# Reload .bash_profile
. ~/.bash_profile

Secure the MariaDB Installation

Use the MariaDB utility to set the database root password

Execute the following commands in Terminal:

# If you stopped the server in the last step, restart it
sudo -b mysqld_safe

# Set the database root password
# It is strongly recommended that you take the default options (hit return)

# Login to your mysql server with mysql command line tool
mysql -u root -p

# Add the -h hostname option if you are operating remotely.
# Use the quit command to exit the mysql command line tool.

# Consider uncommenting the skip-networking option in my.cnf if you don't need to reach the mysql server from the network. If you use this option everything will have to reach the database server through the socket.
sudo nano /etc/my.cnf

Starting MariaDB at Boot Time

The easiest way to start MariaDB at boot time is to download one of the package format (.dmg) versions of MySQL for OS X and run the MySQLStartupItem.pkg, which copies the startup scripts to /Library/StartupItems as part of its installation. Copy the preference pane to either /Library/PreferencePanes or ~/Library/PreferencePanes.

Once you have installed the startup scripts you must create a symbolic link from /usr/local/mysql/support-files/ to /usr/local/mysql/share/mysql/. The preference pane and boot time startup script expect the mysql startup script mysql.server to be located in /usr/local/mysql/suport-files. A data directory is also expected.

# Change directories into the mysql directory
cd /usr/local/mysql

# Create the symbolic link
ln -s share/mysql support-files

# Create the symbolic link to the data directory
sudo ln -s var data


If things are not running as expected, first check the system console log and the MariaDB log for errors in /usr/local/mysql/var/hostname.err.

If ./configure is not working, make sure you downloaded the source code release and not the binary release.

Consider hard coding the host name in my.cnf. Sometimes, at boot time, mysql will start to execute before the network host name has been fixed by the operating system. In the past, mysql could hang if you started it at boot time before networking was initialized and then shut it down later after networking had come up. Trouble can also occur if you start mysql from the command line and then try to stop it from the preference pane. Add the following to my.cnf under [mysqld], where hostname is the name of the host:
pid-file = /usr/local/mysql/var/
If you want to keep things consistent, it's also not a bad idea to add:
log-error = /usr/local/mysql/var/hostname.err as well.

Keep in mind that the packaged version of MariaDB and the source version of MariaDB keep the database files in different directories. The source version in /usr/local/mysql/var and the packaged version in /usr/local/mysql/data.

The packaged version of MariaDB creates the socket in /tmp where as these instructions create the socket at the prescribed OS X server location of /var/mysql. If you are running phpMyAdmin you may have to change the socket location in the configuration file to look something like this: $cfg['Servers'][$i]['socket'] = '/var/mysql/mysql.sock';.

When using the Apple supplied PHP with MariaDB 5.3, you may get a message from phpMyAdmin "Your PHP MySQLDB library version 5.0.45 differs from your MariaDB server version 5.3.12. This may cause unpredictable behavior." Apparently, the Apple supplied PHP has been linked with the MySQL 5.0.x libraries. Either recompile PHP with the MariaDB 5.3.x libraries or use MariaDB 5.0.x.

Useful Links


Did you find this page useful? Did it save you some time? Please visit our sponsor Cyrilla's Artistic Crochet and purchase a fine handcrafted product. You can find beautiful products for babies and children, bag holders to recycle your plastic bags, digital compact camera cases, finger puppets, faux food, kitchen towels, scarves, wine gift bags and more. All products are handmade in the U.S.A.


Please let me know if you found this page useful or have any other comments. Thank you to all who have mailed in your suggestions. Your feedback has helped make this document more accurate and complete.


Your Email (Optional):
Include an email address if you would like a reply.