How to install mariadb on FreeBSD

Recent discussion around mysql license and its future lead me to mariadb.

From Wikipedia

MariaDB is a community-developed branch of the MySQL database, the impetus being the community maintenance of its free status under GPL, as opposed to any uncertainty of MySQL license status under its current ownership by Oracle.

The intent also being to maintain high fidelity with MySQL, ensuring a “drop-in” replacement capability with library binary equivalency and exacting matching with MySQL APIs and commands. It includes the XtraDB storage engine as a replacement for InnoDB.

Its lead developer is Monty Widenius, the founder of MySQL and Monty Program AB.”

dba by night, ninja by nightBeing curious I decide to install mariadb on my Freebsd 8.1 stable . My first option for install is via ports but at time writing I don’t find the mariadb port 🙁

After search and dig google I came up with solution on how to install mariadb from source.

Here the steps :

Add user and group for mariadb

# pw groupadd mysql
# pw adduser mysql -g mysql -d /usr/local/mysql

Download and extract mariadb tarball

# wget -c http://ftp-stud.hs-esslingen.de/pub/Mirrors/mariadb/mariadb-5.1.50/kvm-tarbake-jaunty-x86/mariadb-5.1.50.tar.gz &

#tar xvzf mariadb-5.1.50.tar.gz

#cd mariadb-5.1.50

Configure, make and make install

# ./configure –with-plugins=max-no-ndb


Configuration summary for MariaDB Server version 5.1.50-MariaDB

* Installation prefix:       /usr/local
* System type:               unknown-freebsd8.1
* Host CPU:                  i386
* C Compiler:                gcc (GCC) 4.2.1 20070719  [FreeBSD]
* C++ Compiler:              g++ (GCC) 4.2.1 20070719  [FreeBSD]
* Debug enabled:             no
* Community Features:        yes

Thank you for choosing MariaDB!

# make && make install

# rehash

For more info around configure option you may refer to :

# ./configure –help | more

Initialize and setting mariadb

# ./mysql_install_db

Installing MariaDB/MySQL system tables…
OK
Filling help tables…
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:

/usr/local/bin/mysqladmin -u root password ‘new-password’
/usr/local/bin/mysqladmin -u root -h goten.rasyid.net password ‘new-password’

Alternatively you can run:
/usr/local/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 MySQL manual for more instructions.

# cd /usr/local

# chown -R mysql:mysql var

Start mariadb for first time

# /usr/local/bin/mysqld_safe &

[1] 58333
goten# 101110 10:34:31 mysqld_safe Logging to ‘/usr/local/var/goten.rasyid.net.err’.
101110 10:34:31 mysqld_safe Starting mysqld daemon with databases from /usr/local/var

Check the process

# ps -ax | grep mysql

58333   0  I      0:00.09 /bin/sh /usr/local/bin/mysqld_safe
58375   0  I      0:03.39 /usr/local/libexec/mysqld –basedir=/usr/local –datadir=/usr/local/var –user=mysql –log-error=/

Try to access mariadb

# mysql -uroot -p

Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.1.50-MariaDB Source distribution

This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

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

MariaDB [(none)]> show databases;
+——————–+
| Database           |
+——————–+
| information_schema |
| mysql              |
| test               |
+——————–+
3 rows in set (0.10 sec)

MariaDB [(none)]>

MariaDB [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MariaDB [mysql]>

List the engines inside mariadb

MariaDB [(none)]> SHOW ENGINES\G
*************************** 1. row ***************************
Engine: BLACKHOLE
Support: YES
Comment: /dev/null storage engine (anything you write to it disappears)
Transactions: NO
XA: NO
Savepoints: NO
*************************** 2. row ***************************
Engine: MRG_MYISAM
Support: YES
Comment: Collection of identical MyISAM tables
Transactions: NO
XA: NO
Savepoints: NO
*************************** 3. row ***************************
Engine: FEDERATED
Support: YES
Comment: FederatedX pluggable storage engine
Transactions: YES
XA: NO
Savepoints: YES
*************************** 4. row ***************************

Engine: MARIA
Support: YES
Comment: Crash-safe tables with MyISAM heritage
Transactions: YES
XA: NO
Savepoints: NO
*************************** 5. row ***************************
Engine: CSV
Support: YES
Comment: CSV storage engine
Transactions: NO
XA: NO
Savepoints: NO
*************************** 6. row ***************************
Engine: MEMORY
Support: YES
Comment: Hash based, stored in memory, useful for temporary tables
Transactions: NO
XA: NO
Savepoints: NO

*************************** 7. row ***************************
Engine: ARCHIVE
Support: YES
Comment: Archive storage engine
Transactions: NO
XA: NO
Savepoints: NO
*************************** 8. row ***************************
Engine: MyISAM
Support: DEFAULT
Comment: Default engine as of MySQL 3.23 with great performance
Transactions: NO
XA: NO
Savepoints: NO
*************************** 9. row ***************************
Engine: InnoDB
Support: YES
Comment: Percona-XtraDB, Supports transactions, row-level locking, and foreign keys
Transactions: YES
XA: YES
Savepoints: YES
*************************** 10. row ***************************
Engine: PBXT
Support: YES
Comment: High performance, multi-versioning transactional engine
Transactions: YES
XA: YES
Savepoints: NO
10 rows in set (0.00 sec)

MariaDB [(none)]>

Make mariadb service start at boot time

create new file called mariadb and put in /usr/local/etc/rc.d

# ee /usr/local/etc/rc.d/mariadb

Enter this :

#!/bin/sh

# PROVIDE: mariadb

. /etc/rc.subr

name=”mariadb”
rcvar=`set_rcvar`
start_cmd=”mariadb_start”
stop_cmd=”:”

load_rc_config $name

mariadb_start()
{
if checkyesno ${rcvar}; then
/usr/local/bin/mysqld_safe &
fi
}

run_rc_command “$1”

make the script executable

# chmod +x /usr/local/etc/rc.d/mariadb

Enable the service by adding it to rc.conf

# echo ‘mariadb_enable=”YES”‘ >> /etc/rc.conf

Try restart server to test the script and check it with ps command.

# ps -ax | grep sql

893  ??  Is     0:00.35 /usr/local/bin/postmaster -D /usr/local/pgsql/data (postgres)
903  v0- I      0:00.06 /bin/sh /usr/local/bin/mysqld_safe
955  v0- I      0:04.09 /usr/local/libexec/mysqld –basedir=/usr/local –datadir=/usr/local/var –user=mysql –log-error=/
#

Done.

mariadb successfully installed on my FreeBSD 8.1 box.

Update : click here for how to install mariadb10 on freebsd10.

helpful resources :

  1. changing mysql for mariadb
  2. Quick tutorial on how to create a FreeBSD system startup script

Tags: