If you’re on a Mac, and need a MariaDB server for development, you can install one using MacPorts… but the setup is not self-explanatory.

Today, I will show you how to install MariaDB 10.3 (or any 10.x) server on Mac!

1. MacPorts

First install [MacPorts from here] and then get back to this guide.

2. Installing and setting up MariaDB

Now, open a terminal and run:

sudo port selfupdate
sudo port install mariadb-10.3-server

Which should build and install MariaDB server, and create the _mysql user and group for us.

Now let’s create the database directory and give it the right permissions:

sudo mkdir -p /opt/local/var/db/mariadb-10.3
sudo chown -R _mysql:_mysql /opt/local/var/db/mariadb-10.3

Now let’s create the default database files using the included program, which we will run as the _mysql user:

sudo -u _mysql /opt/local/lib/mariadb-10.3/bin/mysql_install_db

If you want to run MariaDB server over a network (TCP) socket (port 3306) in addition to a UNIX socket, run:

sudo nano /opt/local/etc/mariadb-10.3/my.cnf

And comment out the line with # so that it reads:

#!include /opt/local/etc/mariadb-10.3/macports-default.cnf

Now let’s start the MariaDB server, as the _mysql user, with:

sudo -u _mysql /opt/local/lib/mariadb-10.3/bin/mysqld_safe --datadir='/opt/local/var/db/mariadb-10.3'

You can connect to it to test that it’s working with:


Now let’s secure the installation, setting up passwords and things:


Follow the steps, mostly answering with yes and setting the password.

3. Adding MariaDB to the PATH

Now, typing out these long commands every time is tedious. If you only need one version of MariaDB, we can add it to the path.

macOS Catalina and newer:

nano ~/.zprofile

macOS Mojave and earlier:

nano ~/.bashrc

And add the following contents to the file:

# MariaDB
export PATH="/opt/local/lib/mariadb-10.3/bin/:$PATH"

Now close and reopen your terminal. You should now be able to run the mysql command without the long path. Tip: If you get an error with your username, try mysql -u root.

4. Automatic log-in

Now, typing username and password every time can be annoying, so add your MySQL username and password to a local config file!

nano ~/.my.cnf

And add the following contents:



Of course, replacing those placeholders with your actual username and password.

5. Shutting down MariaDB server

Assuming you added MariaDB to the PATH (point 3) and set up automatic log-in (point 4), you can shut down the MariaDB server with the command:

mysqladmin shutdown

6. Properly starting and stopping MariaDB server

From now on, we won’t start the MariaDB server with a long, ugly command, and instead we can simply run:

sudo port load mariadb-10.3-server

to start, and

sudo port unload mariadb-10.3-server

to stop it again.


While it might seem overwhelming and confusing at first, with my guide it becomes easy as pie! Just make sure to complete all steps, and you’ll be good to go.

Did this guide help you out? I’m an individual doing this in my spare time. Feel free [to donate a coffee] so I can keep this blog going!

That’s all there is to it!