Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 73 additions & 69 deletions tech/database/mariadb/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,103 +5,93 @@ section: tech-database
description: Transactional SQL database, an enhanced drop-in replacement for MySQL.
---

# MariaDB SQL database
# MariaDB

[MariaDB](https://mariadb.org/en/about/) is a drop-in replacement of MySQL, forked by the community from the latter. To learn more about MariaDB, visit [upstream feature page](https://mariadb.com/kb/en/mariadb/mariadb-vs-mysql-features/), and to see main differences from MySQL, see [compatibility documentation](https://mariadb.com/kb/en/mariadb/mariadb-vs-mysql-compatibility/).
[MariaDB server](https://mariadb.org/en/about/) is a community-developed, open source relational database, and an enhanced, drop-in replacement for MySQL. To learn more about MariaDB, visit the [upstream feature page](https://mariadb.com/kb/en/mariadb-vs-mysql-features/), and to see the main differences from MySQL, see the [compatibility documentation](https://mariadb.com/kb/en/mariadb-vs-mysql-compatibility/).

## What implementations of MySQL we have in Fedora
[MariaDB](https://src.fedoraproject.org/rpms/mariadb) is preferred MySQL implementation in Fedora. MariaDB can be usually used instead of MySQL as a drop-in replacement in most practical cases and most of the applications will work exactly the same. However, when you need to install Community MySQL, it is available as [community-mysql package](https://src.fedoraproject.org/rpms/community-mysql) in Fedora repositories.
MariaDB is the preferred MySQL implementation in Fedora. It can usually be used instead of MySQL as a drop-in replacement in most practical cases. However, if you need Community MySQL, it is available as the [mysql8.4 package](https://src.fedoraproject.org/rpms/mysql8.4) in Fedora repositories.

Generally, most of the [documentation for MySQL](http://dev.mysql.com/doc/) is valid also for MariaDB.
## Versions available in Fedora

## What versions do we have in Fedora
Fedora ships only the LTS releases of MariaDB. Currently, several versions are available in parallel, each in its own versioned package (e.g. `mariadb10.11`, `mariadb11.8`).

Fedora usually ships only the most recent stable version of MariaDB.
You can find various (unsupported) versions in the maintainer's [COPR repositories](https://copr.fedorainfracloud.org/coprs/mschorm/).
Learn more about current version at [upstream documentation](https://mariadb.com/kb/en/library/library-mariadb-releases/). The package is called `mariadb` (client tools) and `mariadb-server` (server daemon).
Only one version in each Fedora release is set as the "distribution default", which provides the classic unversioned package names (e.g. `mariadb`, `mariadb-server`).

You can get an older version either by installing [Software Collection package of MariaDB 5.5](https://www.softwarecollections.org/en/scls/rhscl/mariadb55/) or by downloading [packages provided by upstream](https://downloads.mariadb.org/).
To see which MariaDB versions are available in your Fedora release:

Fedora also ships MariaDB with Galera patch. The package with MariaDB Galera is called `mariadb-galera-server` and the wsrep plug-in is available in package `galera`. See section [How to install MariaDB Galera on Fedora](#how-to-install-mariadb-galera-on-fedora) for more information.
```
$ dnf search mariadb | grep server
```

> **Note:** Available versions may differ between Fedora releases. Rawhide may offer newer versions than the current stable release.

## How to install MariaDB on Fedora

In order to install MariaDB client package, run:
To install the distribution default version of MariaDB server:

```
$ sudo dnf install mariadb
$ sudo dnf install mariadb-server
```

In order to install MariaDB server package, run:
In order to install a specific version, use the versioned package names:

```
$ sudo dnf install mariadb-server
$ sudo dnf install mariadb11.8-server
```

If you need to connect to the MariaDB server using GUI, install either phpMyAdmin:
If you need to connect to the MariaDB server using a GUI, install phpMyAdmin:

```
$ sudo dnf install phpMyAdmin
```

Or install Libre Office Base with JDBC plug-in for MariaDB:
Or install LibreOffice Base with the JDBC connector for MariaDB:

```
$ sudo dnf install libreoffice-base mariadb-java-client
```

For connecting to the MariaDB server using ODBC, install `unixODBC` and `mariadb-connector-odbc` packages:
For connecting to the MariaDB server using ODBC:

```
$ sudo dnf install mariadb-connector-odbc
```

## Basic tutorial for MariaDB in Fedora
## Getting started

MariaDB runs on port 3306 by default and creates a local unix socket at `/var/lib/mysql/mysql.sock`. By default, data is stored in the `/var/lib/mysql` directory and logs are located under `/var/log/mariadb/`. In order to change these directories, pay attention to use correct SELinux context and owner.
MariaDB runs on port 3306 by default and creates a local unix socket at `/var/lib/mysql/mysql.sock`. Data is stored in `/var/lib/mysql` and logs are located under `/var/log/mariadb/`. When changing these directories, pay attention to use the correct SELinux context and owner.

Right after installing, the data directory is empty. It is initialized during the first start.

To start MariaDB server, run:
The data directory is initialized automatically during the first start. To start MariaDB server:

```
$ sudo systemctl start mariadb
```

In order to setup MariaDB to start after system reboot, run:
To start MariaDB automatically after reboot:

```
$ sudo systemctl enable mariadb
```

The root user has no password set by default and so it is allowed to connect without the password:
The root user has no password set by default and connects via unix socket authentication:

```
mysql -u root
$ mysql -u root
```

It is suggested to make the MariaDB more secure by running secure installation assistant:

```
$ sudo mysql_secure_installation
```

This tool asks you several questions and you are supposed to answer interactively. Do not provide the system administrator's password for your Linux system here. Use a different strong password, since this is a separate authentication for a MySQL user called "root."

## How to configure MariaDB

Configuration of both, client and server, is done by editing files `/etc/my.cnf`, `~/.my.cnf` and any files under `/etc/my.cnf.d/` with `.cnf` suffix. For more informations how to change configuration, see [the upstream documentation](https://mariadb.com/kb/en/mariadb/server-system-variables/#about-the-server-system-variables).
Configuration of both client and server is done by editing files `/etc/my.cnf`, `~/.my.cnf` and any files under `/etc/my.cnf.d/` with `.cnf` suffix. For more information, see [the upstream documentation](https://mariadb.com/kb/en/server-system-variables/).

### How to configure MariaDB server for local development
### Local development setup

When developing an application that uses MariaDB as the storage engine, developers typically use one user account that has full access to one dedicated database scheme. In order to do so, run the commands from section [Basic tutorial for MariaDB in Fedora](#basic-tutorial-for-mariadb-in-fedora) and then create the user and the dedicated database:
When developing an application that uses MariaDB, developers typically create a dedicated database and user:

```
$ sudo systemctl start mariadb
$ sudo systemctl enable mariadb
$ sudo mysql_secure_installation
...My Account sudo mysql -u root -p
MariaDB [(none)]> create database db1;
$ sudo mysql -u root
MariaDB [(none)]> CREATE DATABASE db1;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> CREATE USER 'valeria'@'localhost' IDENTIFIED BY 'secretpass';
Expand All @@ -114,44 +104,45 @@ MariaDB [(none)]> exit
Bye
```

After that you may access the database from MariaDB command-line tool by running:
After that, access the database by running:

```
$ mysql -u valeria -p
```

By specifying `-p` without password, you'll be asked for the password interactively.
By specifying `-p` without a password, you will be asked for the password interactively.

In various frameworks or libraries, you will usually use the username, password and database to access the database.

### How to run MariaDB in production development
### Production deployment

In order to run MariaDB in production development, you should pay extra attention to setting up the service in order to minimize the risk of being exploited. Among other things, this means:
When running MariaDB in production, pay extra attention to security:

* use `mysql_secure_installation` as mentioned above
* do not accept connections from all addresses unless absolutely necessary
* Do not accept connections from all addresses unless absolutely necessary
* **Always use a strong password**
* Limit user permissions to those necessary for the application to run
* Run SELinux in enforcing mode and set up the policy properly
* Keep your system and MariaDB updated
* Monitor your MariaDB and system logs

By default, MariaDB cannot be accessed from another computer. In order to allow access from another computer, we need to do the following things.
By default, MariaDB cannot be accessed from another computer. To allow remote access:

Allow to accept connections on port 3306:
Allow connections on port 3306:

```
firewall-cmd --permanent --zone=public --add-port=3306/tcp
$ sudo firewall-cmd --permanent --zone=public --add-port=3306/tcp
$ sudo firewall-cmd --reload
```

Allow to listen on all interfaces (or your preferred network interface) by adding configuration option:
Allow listening on all interfaces (or your preferred network interface) by adding this configuration option:

```
bind-address = 0.0.0.0
```

### Other common configuration
### Common configuration options

In order to change configuration parameters for the MariaDB server, create the a configuration file under `/etc/my.cnf.d/` directory.

The following example shows content of the file `/etc/my.cnf.d/myconfig.cnf` which contains several commonly changed options (use any variables that matches your needs).
To change configuration, create a file under `/etc/my.cnf.d/`. The following example shows `/etc/my.cnf.d/myconfig.cnf` with commonly changed options:

```
# The maximum permitted number of simultaneous client connections:
Expand All @@ -161,7 +152,7 @@ max_connections = 20
ft_min_word_len = 3

# The maximum length of the word to be included in a FULLTEXT index:
ft_max_word_len = My Account
ft_max_word_len = 20

# In case the native AIO is broken, it can be disabled by:
innodb_use_native_aio = 0
Expand All @@ -175,46 +166,59 @@ general_log = 1
general_log_file = "/var/log/mariadb/query.log"
```

After changing the configuration, restart the daemon using `$ sudo systemctl restart mariadb`.
After changing the configuration, restart the daemon: `$ sudo systemctl restart mariadb`.

## How to get an encrypted connection

## <a name="how-to-install-mariadb-galera-on-fedora"></a>How to install MariaDB Galera on Fedora
For the proper TLS setup, you should first [add a TLS certificate](/en/docs/system-services/tls/certificates/) to your system.

## How to install MariaDB Galera on Fedora

MariaDB Galera Cluster is a synchronous multi-master cluster for MariaDB.

In order to install MariaDB Galera server package, run:
To install MariaDB Galera server:

```
$ sudo dnf install mariadb-galera-server galera
$ sudo dnf install mariadb-server-galera
```

MariaDB Galera uses several packages from base MariaDB and also provides the same service name. Thus, for starting MariaDB Galera, run:
MariaDB Galera uses several packages from base MariaDB and provides the same service name. To start MariaDB Galera:

```
$ sudo systemctl start mariadb
```

## How to get MariaDB as Docker container
## How to get a MariaDB container

```
$ sudo docker pull fedora/mariadb
$ podman pull quay.io/fedora/mariadb-118
```

For other versions, see available images at [quay.io/organization/fedora](https://quay.io/organization/fedora).

## How to extend MariaDB server by installing extensions available in Fedora

[MariaDB Connect Storage Engine](https://mariadb.com/kb/en/mariadb/connect/) enables MariaDB to access external local or remote data (MED). In order to install this engine, run:
[MariaDB Connect Storage Engine](https://mariadb.com/kb/en/connect/) enables MariaDB to access external local or remote data (MED):

```
$ dnf install mariadb-connect-engine
$ sudo dnf install mariadb-connect-engine
```

In order to install [The Open Query GRAPH computation engine](https://mariadb.com/kb/en/mariadb/oqgraph-storage-engine/), run:
[The Open Query GRAPH computation engine (OQGraph)](https://mariadb.com/kb/en/oqgraph-storage-engine/):

```
$ dnf install mariadb-oqgraph-engine
$ sudo dnf install mariadb-oqgraph-engine
```

## MariaDB server available as a dynamic library:
## MariaDB server available as a dynamic library

MariaDB server is also available as a dynamic library (`libmysqld.so`) in the package `mariadb-embedded`. Header files for building applications against this library are in `mariadb-embedded-devel`.

However, the use of the embedded library is discouraged. MySQL 8 dropped the embedded library and MariaDB is expected to follow in the same direction.

In Fedora, MariaDB server is available also as a dynamic library, that can be handy in some applications. This library (`libmysqld.so`) is available in the package `mariadb-embedded` and header files for building an application against this library are available in the package `mariadb-embedded-devel`.
## See also

However the use of the embedded library is discouraged. MySQL 8 dropped the embedded library and I expect MariaDB to go in the same direction.
- [Official MariaDB documentation](https://mariadb.com/kb/en/)
- [MariaDB Release Notes](https://mariadb.com/kb/en/release-notes/)
- [MySQL documentation](https://dev.mysql.com/doc/) — mostly applicable to MariaDB as well
- [MariaDB vs MySQL compatibility](https://mariadb.com/kb/en/mariadb-vs-mysql-compatibility/)