Installing MariaDB Server on Mac OS X with Homebrew

Back in 2016, we blogged about deploying MariaDB 10.1.16 on Mac OS X with Homebrew. Homebrew now includes MariaDB 10.4, 10.3, 10.2, and 10.1 for macOS. We’ve refreshed this blog to reflect the latest technology. If you need the old blog, you can find it here.

1. Install Xcode

Run xcode-select --install.

$ xcode-select --install
xcode-select: note: install requested for command line developer tools

2. Install Homebrew

Run /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)".

$  /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
==> This script will install:
/usr/local/bin/brew
/usr/local/share/doc/homebrew
/usr/local/share/man/man1/brew.1
/usr/local/share/zsh/site-functions/_brew
/usr/local/etc/bash_completion.d/brew
/usr/local/Homebrew
==> The following new directories will be created:
/usr/local/sbin
/usr/local/Caskroom
 
Press RETURN to continue or any other key to abort
Password:
==> /usr/bin/sudo /bin/mkdir -p /usr/local/sbin /usr/local/Caskroom
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/sbin /usr/local/Caskroom
==> /usr/bin/sudo /usr/sbin/chown rob /usr/local/sbin /usr/local/Caskroom
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/sbin /usr/local/Caskroom
==> Downloading and installing Homebrew...
remote: Enumerating objects: 5822, done.
remote: Counting objects: 100% (5822/5822), done.
remote: Compressing objects: 100% (43/43), done.
remote: Total 24553 (delta 5779), reused 5821 (delta 5779), pack-reused 18731
Receiving objects: 100% (24553/24553), 7.33 MiB | 1.09 MiB/s, done.
Resolving deltas: 100% (18413/18413), completed with 1257 local objects.
...
HEAD is now at 67d1bc6fb Merge pull request #7615 from Bo98/test-dep-satisfied
==> Downloading https://homebrew.bintray.com/bottles-portable-ruby/portable-ruby-2.6.3.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring portable-ruby-2.6.3.mavericks.bottle.tar.gz
Updated 1 tap (homebrew/core).
==> New Formulae
...
==> Renamed Formulae
...
==> Deleted Formulae
...
==> Installation successful!
 
==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
  https://docs.brew.sh/Analytics
No analytics data has been sent yet (or will be during this `install` run).
 
==> Homebrew is run entirely by unpaid volunteers. Please consider donating:
  https://github.com/Homebrew/brew#donations
 
==> Next steps:
- Run `brew help` to get started
- Further documentation: 
    https://docs.brew.sh

3. Check Homebrew

Run brew doctor. Follow on-screen instructions to fix warnings if necessary.

$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers with debugging if you file an issue. If everything you use Homebrew for is working fine: please don't worry or file an issue; just ignore this. Thanks!
 
Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on those kegs to fail to run properly once built. Run `brew link` on these:
  gettext
  git
 
Warning: Some installed formulae are missing dependencies.
You should `brew install` the missing dependencies:
  brew install openssl@1.1
 
Run `brew missing` for more details.
$ brew link gettext git
Linking /usr/local/Cellar/gettext/0.19.8.1... 187 symlinks created
Linking /usr/local/Cellar/git/2.19.1... 
Error: Could not symlink bin/git
Target /usr/local/bin/git
already exists. You may want to remove it:
  rm '/usr/local/bin/git'
 
To force the link and overwrite all conflicting files:
  brew link --overwrite git
 
To list all files that would be deleted:
  brew link --overwrite --dry-run git
 
...

4. Update Homebrew

Run brew update.

$ brew update
Already up-to-date.

5. Verify MariaDB version in Homebrew repo

Run brew info mariadb.

$ brew info mariadb
mariadb: stable 10.4.13 (bottled)
Drop-in replacement for MySQL
MariaDB Foundation
Conflicts with: mariadb-connector-c (because both install plugins) mysql (because mariadb, mysql, and percona install the same binaries) mytop (because both install `mytop` binaries) percona-server (because mariadb, mysql, and percona install the same binaries) /usr/local/Cellar/mariadb/10.2.14 (641 files, 168.6MB) Poured from bottle on 2018-04-30 at 11:34:15 /usr/local/Cellar/mariadb/10.3.10 (652 files, 173.3MB) * Built from source on 2018-10-12 at 07:16:37 From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/mariadb.rb ==> Dependencies Build: cmake ✘, pkg-config ✘ Required: groonga ✘, openssl@1.1 ✔ ==> Caveats A "/etc/my.cnf" from another install may interfere with a Homebrew-built server starting up correctly. MySQL is configured to only allow connections from localhost by default To have launchd start mariadb now and restart at login: brew services start mariadb Or, if you don't want/need a background service you can just run: mysql.server start ==> Analytics install: 15,161 (30 days), 36,985 (90 days), 172,584 (365 days) install-on-request: 14,780 (30 days), 36,286 (90 days), 168,365 (365 days) build-error: 0 (30 days)

6. Install MariaDB

Run brew install mariadb. Follow on-screen instructions to upgrade if necessary to upgrade a previously installed version.

$ brew install mariadb
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
fonttools                                                           timidity
 
==> Downloading https://homebrew.bintray.com/bottles/mecab-0.996.mojave.bottle.3.tar.gz
==> Downloading from https://akamai.bintray.com/ef/[...]?__gda__=exp=1590016
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/mecab-ipadic-2.7.0-20070801.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/30/[...]?__gda__=exp=1590016
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/msgpack-3.2.1.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/3b/[...]?__gda__=exp=1590016
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/pcre-8.44.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/ed/[...]?__gda__=exp=1590016
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/groonga-10.0.2.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/df/[...]?__gda__=exp=1590016
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/mariadb-10.4.13.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/e4/[...]?__gda__=exp=1590016
######################################################################## 100.0%
Error: mariadb 10.3.10 is already installed
To upgrade to 10.4.13, run `brew upgrade mariadb`.
 
$ brew upgrade mariadb
==> Upgrading 1 outdated package:
mariadb 10.3.10 -> 10.4.13
==> Upgrading mariadb 10.3.10 -> 10.4.13 
==> Downloading https://homebrew.bintray.com/bottles/cmake-3.17.2.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/ed/[...]?__gda__=exp=1590016
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/pkg-config-0.29.2_3.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/0d/[...]?__gda__=exp=1590016
######################################################################## 100.0%
==> Downloading https://homebrew.bintray.com/bottles/mecab-0.996.mojave.bottle.3.tar.gz
Already downloaded: /Users/rob/Library/Caches/Homebrew/downloads/[...]--mecab-0.996.mojave.bottle.3.tar.gz
==> Downloading https://homebrew.bintray.com/bottles/mecab-ipadic-2.7.0-20070801.mojave.bottle.tar.gz
Already downloaded: /Users/rob/Library/Caches/Homebrew/downloads/[...]--mecab-ipadic-2.7.0-20070801.mojave.bottle.tar.gz
==> Downloading https://homebrew.bintray.com/bottles/msgpack-3.2.1.mojave.bottle.tar.gz
Already downloaded: /Users/rob/Library/Caches/Homebrew/downloads/[...]--msgpack-3.2.1.mojave.bottle.tar.gz
==> Downloading https://homebrew.bintray.com/bottles/pcre-8.44.mojave.bottle.tar.gz
Already downloaded: /Users/rob/Library/Caches/Homebrew/downloads/[...]--pcre-8.44.mojave.bottle.tar.gz
==> Downloading https://homebrew.bintray.com/bottles/groonga-10.0.2.mojave.bottle.tar.gz
Already downloaded: /Users/rob/Library/Caches/Homebrew/downloads/[...]--groonga-10.0.2.mojave.bottle.tar.gz
==> Downloading https://downloads.mariadb.com/MariaDB/mariadb-10.4.13/source/mariadb-10.4.13.tar.gz
######################################################################## 100.0%
==> Installing dependencies for mariadb: cmake, pkg-config, mecab, mecab-ipadic, msgpack, pcre and groonga
==> Installing mariadb dependency: cmake
==> Pouring cmake-3.17.2.mojave.bottle.tar.gz
==> Caveats
Emacs Lisp files have been installed to:
  /usr/local/share/emacs/site-lisp/cmake
==> Summary
🍺  /usr/local/Cellar/cmake/3.17.2: 6,156 files, 58.1MB
==> Installing mariadb dependency: pkg-config
==> Pouring pkg-config-0.29.2_3.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/pkg-config/0.29.2_3: 11 files, 623.6KB
==> Installing mariadb dependency: mecab
==> Pouring mecab-0.996.mojave.bottle.3.tar.gz
🍺  /usr/local/Cellar/mecab/0.996: 20 files, 4.2MB
==> Installing mariadb dependency: mecab-ipadic
==> Pouring mecab-ipadic-2.7.0-20070801.mojave.bottle.tar.gz
==> Caveats
To enable mecab-ipadic dictionary, add to /usr/local/etc/mecabrc:
  dicdir = /usr/local/lib/mecab/dic/ipadic
==> Summary
🍺  /usr/local/Cellar/mecab-ipadic/2.7.0-20070801: 16 files, 50.6MB
==> Installing mariadb dependency: msgpack
==> Pouring msgpack-3.2.1.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/msgpack/3.2.1: 757 files, 5.2MB
==> Installing mariadb dependency: pcre
==> Pouring pcre-8.44.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/pcre/8.44: 204 files, 5.5MB
==> Installing mariadb dependency: groonga
==> Pouring groonga-10.0.2.mojave.bottle.tar.gz
🍺  /usr/local/Cellar/groonga/10.0.2: 886 files, 39.5MB
==> Installing mariadb
==> cmake . -DMYSQL_DATADIR=/usr/local/var/mysql -DINSTALL_INCLUDEDIR=include/mysql -DINSTALL_MANDIR=share/man -DINSTALL_DOCDIR=share/d
==> make
==> make install
==> Not running post_install as we're building a bottle
You can run it manually using `brew postinstall mariadb`
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built server starting up correctly.
 
MySQL is configured to only allow connections from localhost by default
 
To have launchd start mariadb now and restart at login:
  brew services start mariadb
Or, if you don't want/need a background service you can just run:
  mysql.server start
==> Summary
🍺  /usr/local/Cellar/mariadb/10.4.13: 737 files, 170.0MB, built in 8 minutes 53 seconds
Removing: /usr/local/Cellar/mariadb/10.2.14... (641 files, 168.6MB)
Removing: /usr/local/Cellar/mariadb/10.3.10... (652 files, 173.3MB)
Removing: /Users/rob/Library/Caches/Homebrew/mariadb--10.3.10.tar.gz... (67.2MB)
==> Checking for dependents of upgraded formulae...
==> No dependents found!
==> Caveats
==> cmake
Emacs Lisp files have been installed to:
  /usr/local/share/emacs/site-lisp/cmake
==> mecab-ipadic
To enable mecab-ipadic dictionary, add to /usr/local/etc/mecabrc:
  dicdir = /usr/local/lib/mecab/dic/ipadic
==> mariadb
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.
 
MySQL is configured to only allow connections from localhost by default
 
To have launchd start mariadb now and restart at login:
  brew services start mariadb
Or, if you don't want/need a background service you can just run:
  mysql.server start

7. Run the database installer

Run mysql_install_db. Follow on-screen instructions to upgrade if necessary to upgrade a previously installed version.

$ mysql_install_db
WARNING: The host 'robs-MacBook-Pro-2.local' could not be looked up with /usr/local/Cellar/mariadb/10.4.13/bin/resolveip.
This probably means that your libc libraries are not 100 % compatible
with this binary MariaDB version. The MariaDB daemon, mysqld, should work normally with the exception that host name resolving will not work.
This means that you should use IP addresses instead of hostnames
when specifying MariaDB privileges !
mysql.user table already exists!
Run mysql_upgrade, not mysql_install_db
 
$ mysql_upgrade
Phase 1/7: Checking and upgrading mysql database
Processing databases
...
Phase 7/7: Running 'FLUSH PRIVILEGES'
OK

8. Start MariaDB

Run mysql.server start.

$ mysql.server start
Starting MySQL
. SUCCESS!

9. Secure the installation

If you are installing MariaDB 10.4.6 or later:
Run mariadb-secure-installation.
If you are installing an earlier version of MariaDB:
Run mysql_secure_installation.

NOTE: If you are unsure about using unix_socket, do not enable it when asked.
NOTE: Set a root password even if the on-screen instructions tell you it is safe not to do so.

$ mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.
 
Enter current password for root (enter for none): 
OK, successfully used password, moving on
 
Setting the root password or using the unix_socket ensures that nobody can log into the MariaDB root user without the proper authorisation.
Enable unix_socket authentication? [Y/n] n
 ... skipping.
 
You already have your root account protected, so you can safely answer 'n'.
 
Change the root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully! 
 
By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them.  This is intended only for testing, and to make the installation go a bit smoother.  You should remove them before moving into a production environment.
 
Remove anonymous users? [Y/n] y
 ... Success!
 
Normally, root should only be allowed to connect from 'localhost'.  This ensures that someone cannot guess at the root password from the network.
 
Disallow root login remotely? [Y/n] y
 ... Success!
 
By default, MariaDB comes with a database named 'test' that anyone can access.  This is also intended only for testing, and should be removed before moving into a production environment.
 
Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
 
Reloading the privilege tables will ensure that all changes made so far will take effect immediately.
 
Reload privilege tables now? [Y/n] y
 ... Success!
 
Cleaning up...
 
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
 
Thanks for using MariaDB!

10. Connect to MariaDB

Run mariadb -u root -p.

If you’ve installed an older version of mariadb you may need to use “mysql -u root -p” in the above command.

$ mariadb -u root -p 
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 52
Server version: 10.4.13-MariaDB Homebrew
 
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
 
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>