MariaDB

Updated 19 February 2020

MariaDB

MariaDB is a MySQL fork developed under a GNU GPL licence.

Installation

First install MariaDB as a package:

emerge -a dev-db/mariadb

Make basic settings and set the root password:

emerge --config dev-db/mariadb
Configuring pkg...
 * Trying to get password for mysql 'root' user from 'mysql' section ...
 * Trying to get password for mysql 'root' user from 'client' section ...
 * Please provide a password for the mysql 'root' user now
 * or through the /root/.my.cnf file.
 * Avoid ["'\_%] characters in the password
    > 
 * Retype the password
    > 
 * Creating the mysql database and setting proper permissions on it ...
...

This is a verbose output.

Run MariaDB:

/etc/init.d/mysql start

Add the SQL server to autostart:

rc-update add mysql

Authorized database access

Example of database and user creation

Create a new database, dbtest and a new user, test to work with it:

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.2.29-MariaDB-log Source distribution

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)]> CREATE DATABASE dbtest;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> CREATE USER 'test'@'localhost' IDENTIFIED BY 'secret';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL ON dbtest.* TO 'test'@'localhost';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> Bye

The necessary database and user will be created.

Check the connection to the database:

mysql -u test -d dbtest -p
Enter password: 
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 156
Server version: 10.2.29-MariaDB-log Source distribution

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 [piwigo]> Bye

Backup and restore MariaDB databases

Create a backup of testdb under user test, testdb-dump.sql. To do this, run:

mysqldump -u test -p testdb > testdb-dump.sql

Restore testdb under user test. Use the testdb-dump.sql backup copy. To do this, run:

mysql -u test -p testdb < testdb-dump.sql