There are no notfications.

This article was last reviewed for Debian 9 (Stretch).

MariaDB installation and configuration (Debian, repository)

MariaDB installation and configuration (Debian, repository)
Author: Stefán Örvar Sigmundsson
Initial publication:
Last updated:
Written in: English (United Kingdom)

MariaDB is a fork of MySQL, the world's most popular open-source relational database management system (RDBMS). This article will demonstrate how to install and configure MariaDB on Debian or its derivatives such as Ubuntu and Linux Mint.

Installation

MariaDB can be installed from the official Debian repository using APT:

root@computer:~# apt --assume-yes install mariadb-server

Configuration

A file is created to contain the error log for MariaDB in a dedicated directory:

root@computer:~# touch /var/log/mysql/error.log

A directory is created to contain the temporary files created by MariaDB for various purposes:

root@computer:~# mkdir /var/tmp/mysql

There is a lot of clutter in the default configuration file even though it is operational. Clearing it will ensure that there is no conflict nor confusion:

root@computer:~# > /etc/mysql/mariadb.cnf

mariadb.cnf

The mariadb.cnf file contains MariaDB's primary configuration:

[client]

port = 3306

[mysqld]

basedir = /usr/

bind-address = 127.0.0.1

character-set-server = utf8mb4

collation-server = utf8mb4_unicode_520_ci

datadir = /var/lib/mysql/

log-error = /var/log/mysql/error.log

pid-file = /run/mysqld/mysqld.pid

port = 3306

socket = /run/mysqld/mysqld.sock

tmpdir = /var/tmp/mysql/

user = mysql
[client]
Sets the configuration scope for the subsequent directives to client. The client scope includes all of the client programs that come in the installed software packages so that they need no be configured individually.
port = 3306
The port to which to connect.
[mysqld]
Sets the configuration scope for the subsequent directives to mysqld. The name of the MariaDB service is mysqld by default on Debian.
basedir = /usr/
The base directory is /usr/ by default on Debian.
bind-address = 127.0.0.1
The IP address to which to listen for connections.
character-set-server = utf8mb4
The default character set for the server.
collation-server = utf8mb4_unicode_520_ci
The default collation for the server.
datadir = /var/lib/mysql/
The data directory of MariaDB is /var/lib/mysql/ by default on Debian.
log-error = /var/log/mysql/error.log
The log file of MariaDB is /var/log/mysql/error.log by default on Debian.
pid-file = /var/run/mysqld/mysqld.pid
The PID file of MariaDB.
port = 3306
The port to which to listen on for connections.
socket = /run/mysqld/mysqld.sock
The socket file of MariaDB.
tmpdir = /var/tmp/mysql/
A directory (/var/tmp/mysql/) is created to contain temporary files.
user = mysql
The OS user of MariaDB is mysql by default on Debian.

Conclusion

Log rotation

The package installs a default logrotate configuration file (/etc/logrotate.d/mysql-server) that can be customised:

/var/log/mysql/*.log
{
	copytruncate
	maxage 365
	missingok
	monthly
	notifempty
	rotate 12
}
/var/log/mysql/*.log
Sets the configuration scope for the subsequent section. The pattern matches all files (*) ending with the extension log in the /var/log/mysql/ directory.
copytruncate
Copy the contents of the log file being rotated into a new file and then truncate the original log file.
maxage 365
Remove log files older than 365 days.
missingok
Do not consider it an error if a log file is missing.
monthly
Perform a log rotation monthly.
notifempty
Do not perform a log rotation on an empty log file.
rotate 12
Perform 12 log rotations before older log files are removed.

Directory ownership and permissions

The configuration directory should be protected:

root@computer:~# chown --recursive root:adm /etc/mysql/
root@computer:~# chmod --recursive 0770 /etc/mysql/

The log directory should be protected:

root@computer:~# chown --recursive mysql:adm /var/log/mysql/
root@computer:~# chmod --recursive 0750 /var/log/mysql/

The temporary file directory should be protected:

root@computer:~# chown --recursive mysql:mysql /var/tmp/mysql/
root@computer:~# chmod --recursive 0770 /var/tmp/mysql/

Server reinitiation

MariaDB is restarted when the configuration is done:

root@computer:~# systemctl restart mariadb.service

External links

This article has additional content here.