April 30, 2014

Installing MariaDB 10.0.10 on Mac OS X with Homebrew

Developing on your Mac? Get the latest stable MariaDB version set up on OS X easily with Homebrew. See this step by step guide on installing MariaDB 10.0.10 by Ben Stillman. If you do already have Xcode and Homebrew installed, skip to step 4.

1 Install Xcode

xcode-select --install

bens-mbp:~ ben$ xcode-select --install
xcode-select: note: install requested for command line developer tools

2 Install Homebrew

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

bens-mbp:~ ben$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1
==> The following directories will be made group writable:
/usr/local/.
/usr/local/share
/usr/local/share/man
/usr/local/share/man/man1

==> The following directories will have their group set to admin:
/usr/local/.
/usr/local/share
/usr/local/share/man
/usr/local/share/man/man1
Press RETURN to continue or any other key to abort
bens-mbp:~ ben$ xcode-select --install
xcode-select: note: install requested for command line developer tools
bens-mbp:~ ben$ ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1
==> The following directories will be made group writable:
/usr/local/.
/usr/local/share
/usr/local/share/man
/usr/local/share/man/man1
==> The following directories will have their group set to admin:
/usr/local/.
/usr/local/share
/usr/local/share/man
/usr/local/share/man/man1

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/. /usr/local/share /usr/local/share/man
/usr/local/share/man/man1
Password:
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/. /usr/local/share /usr/local/share/man
/usr/local/share/man/man1
==> /usr/bin/sudo /bin/mkdir /Library/Caches/Homebrew
==> /usr/bin/sudo /bin/chmod g+rwx /Library/Caches/Homebrew
==> Downloading and installing Homebrew...
remote: Counting objects: 166564, done.
remote: Compressing objects: 100% (46782/46782), done.
remote: Total 166564 (delta 118679), reused 166545 (delta 118666)
Receiving objects: 100% (166564/166564), 31.57 MiB | 8.56 MiB/s, done.
Resolving deltas: 100% (118679/118679), done.
From https://github.com/Homebrew/homebrew
* [new branch] master -> origin/master
HEAD is now at a5e73d4 datomic 0.9.4718
==> Installation successful!
You should run `brew doctor' *before* you install anything.
Now type: brew help

3 Check Homebrew

brew doctor

bens-mbp:~ ben$ brew doctor
Your system is ready to brew.

4 Update Homebrew

brew update

bens-mbp:~ ben$ brew update
Already up-to-date.

5 Verify MariaDB Version in Homebrew Repo

brew info mariadb

bens-mbp:~ ben$ brew info mariadb
mariadb: stable 10.0.10 (bottled)
http://mariadb.org/
Conflicts with: mysql, mysql-cluster, mysql-connector-c, percona-server
Not installed
From: https://github.com/Homebrew/homebrew/commits/master/Library/Formula/mariadb.rb
==> Dependencies
Build: cmake ✘
==> Options
--enable-local-infile
Build with local infile loading support
--universal
Build a universal binary
--with-archive-storage-engine
Compile with the ARCHIVE storage engine enabled
--with-bench
Keep benchmark app when installing
--with-blackhole-storage-engine
Compile with the BLACKHOLE storage engine enabled
--with-embedded
Build the embedded server
--with-libedit
Compile with editline wrapper instead of readline
--with-tests
Keep test when installing
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To connect:
mysql -uroot

To have launchd start mariadb at login:
ln -sfv /usr/local/opt/mariadb/*.plist ~/Library/LaunchAgents
Then to load mariadb now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
Or, if you don't want/need launchctl, you can just run:
mysql.server start

6 Install MariaDB

brew install mariadb

bens-mbp:~ ben$ brew install mariadb
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/mariadb-
10.0.10.mavericks.bottle.tar.gz
######################################################################## 100.0%
==> Pouring mariadb-10.0.10.mavericks.bottle.tar.gz
==> Caveats
A "/etc/my.cnf" from another install may interfere with a Homebrew-built
server starting up correctly.

To connect:
mysql -uroot

To have launchd start mariadb at login:
ln -sfv /usr/local/opt/mariadb/*.plist ~/Library/LaunchAgents
Then to load mariadb now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
Or, if you don't want/need launchctl, you can just run:
mysql.server start
==> /usr/local/Cellar/mariadb/10.0.10/bin/mysql_install_db --verbose --user=ben
--basedir=/usr/local/Cellar/mariadb/10.0.10 --datadir=/usr/local/va
==> Summary
/usr/local/Cellar/mariadb/10.0.10: 524 files, 125M

7 Run the Database Installer

unset TMPDIR cd /usr/local/Cellar/mariadb/10.0.10/ mysql_install_db

bens-mbp:~ ben$ unset TMPDIR
bens-mbp:~ ben$ cd /usr/local/Cellar/mariadb/10.0.10/
bens-mbp:10.0.10 ben$ mysql_install_db
Installing MariaDB/MySQL system tables in './data' ...
140416 12:00:59 [Note] InnoDB: The InnoDB memory heap is disabled
140416 12:00:59 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
140416 12:00:59 [Note] InnoDB: Compressed tables use zlib 1.2.5
140416 12:00:59 [Note] InnoDB: Using CPU crc32 instructions
140416 12:00:59 [Note] InnoDB: Initializing buffer pool, size = 128.0M
140416 12:00:59 [Note] InnoDB: Completed initialization of buffer pool
140416 12:00:59 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to
be created!
140416 12:00:59 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
140416 12:00:59 [Note] InnoDB: Database physically writes the file full: wait...
140416 12:00:59 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
140416 12:00:59 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
140416 12:00:59 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
140416 12:00:59 [Warning] InnoDB: New log files created, LSN=45781
140416 12:00:59 [Note] InnoDB: Doublewrite buffer not found: creating new
140416 12:00:59 [Note] InnoDB: Doublewrite buffer created
140416 12:00:59 [Note] InnoDB: 128 rollback segment(s) are active.
140416 12:00:59 [Warning] InnoDB: Creating foreign key constraint system tables.
140416 12:00:59 [Note] InnoDB: Foreign key constraint system tables created
140416 12:00:59 [Note] InnoDB: Creating tablespace and datafile system tables.
140416 12:00:59 [Note] InnoDB: Tablespace and datafile system tables created.

140416 12:00:59 [Note] InnoDB: Waiting for purge to start
140416 12:00:59 [Note] InnoDB: Percona XtraDB (http://www.percona.com) 5.6.15-63.0 started; log sequence
number 0
140416 12:01:00 [Note] InnoDB: FTS optimize thread exiting.
140416 12:01:00 [Note] InnoDB: Starting shutdown...
140416 12:01:01 [Note] InnoDB: Shutdown completed; log sequence number 1619048
OK
Filling help tables...
140416 12:01:01 [Note] InnoDB: The InnoDB memory heap is disabled
140416 12:01:01 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
140416 12:01:01 [Note] InnoDB: Compressed tables use zlib 1.2.5
140416 12:01:01 [Note] InnoDB: Using CPU crc32 instructions
140416 12:01:01 [Note] InnoDB: Initializing buffer pool, size = 128.0M
140416 12:01:01 [Note] InnoDB: Completed initialization of buffer pool
140416 12:01:01 [Note] InnoDB: Highest supported file format is Barracuda.
140416 12:01:01 [Note] InnoDB: 128 rollback segment(s) are active.
140416 12:01:01 [Note] InnoDB: Waiting for purge to start
140416 12:01:01 [Note] InnoDB: Percona XtraDB (http://www.percona.com) 5.6.15-63.0 started; log sequence
number 1619048
140416 12:01:01 [Note] InnoDB: FTS optimize thread exiting.
140416 12:01:01 [Note] InnoDB: Starting shutdown...
140416 12:01:02 [Note] InnoDB: Shutdown completed; log sequence number 1619058
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

'./bin/mysqladmin' -u root password 'new-password'
'./bin/mysqladmin' -u root -h bens-mbp.roving.com password 'new-password'

Alternatively you can run:
'./bin/mysql_secure_installation'

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '.' ; ./bin/mysqld_safe --datadir='./data'

You can test the MariaDB daemon with mysql-test-run.pl
cd './mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Support MariaDB development by buying support/new features from
SkySQL Ab. You can contact us about this at sales@skysql.com.
Alternatively consider joining our community based development effort:
http://mariadb.com/kb/en/contributing-to-the-mariadb-project/

8 Start MariaDB

mysql.server start

bens-mbp:10.0.10 ben$ mysql.server start
Starting MySQL
. SUCCESS!

9 Secure the Installation

mysql_secure_installation

bens-mbp:10.0.10 ben$ mysql_secure_installation
/usr/local/bin/mysql_secure_installation: line 379: find_mysql_client: command not found

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
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!

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]
... 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]
... 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]
- 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]
... 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

mysql -u root -p

bens-mbp:10.0.10 ben$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 10.0.10-MariaDB Homebrew

Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

11 Verify MariaDB Version

select @@version;

MariaDB [(none)]> select @@version;
+-----------------+
| @@version |
+-----------------+
| 10.0.10-MariaDB |
+-----------------+
1 row in set (0.00 sec)
About Ben Stillman

Ben Stillman is a Principal Consultant working with MariaDB and MySQL.

Read all posts by Ben Stillman