Updated 15 March 2019


This article describes how to install and configure the MariaDB database service. It covers methods of handling databases both in a Web browser interface with PhpMyAdmin and from the command line. In the following example, installing on a Calculate Scratch Server will be considered.

Installing and configuring MariaDB


emerge -av mariadb

Preliminary settings

First let us set the MariaDataBase root password. Remember this is not your system 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
    > choose a root password
 * Retype the password
    > reenter the password
 * Creating the mysql database and setting proper permissions on it ...


Start the service

/etc/init.d/mysql start

Stop the service

/etc/init.d/mysql stop

Restart the service

/etc/init.d/mysql restart

Add to autostart:

rc-update add mysql default

Use MariaDB in command line

Connect to database server

# mysql -u root -p
Enter password: enter the root password here
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 100985
Server version: 5.5.50-MariaDB MariaDB Server
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>

View database info

To list all existing databases:

MariaDB [(none)]> SHOW DATABASES;

To view a database with parameters (wiki in this example):

MariaDB [(none)]> SHOW CREATE DATABASE `wiki`;

To connect to a specific database:

MariаDB [(none)]> USE wiki;

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
MariаDB [wiki]>

To view all tables from the database:

MariаDB [wiki]> SHOW tables;

View a table:

MariаDB [wiki]> SELECT * FROM page;

h2. Add database, user and access privileges

To add a database with parameters:

MariаDB [(none)]> CREATE DATABASE `base` CHARACTER SET utf8 COLLATE utf8_general_ci;

To add a user:

MariаDB [(none)]> CREATE USER base_user@localhost IDENTIFIED BY 'ПАРОЛЬ';

To allocate a user to the database:

MariaDB [(none)]> GRANT ALL PRIVILEGES ON base.* to base_user@localhost;

Always update access rights before quitting:


Quit MariaDB in command line

To quit, use the 'exit' command:

MariаDB [(none)]> exit

Backup and restore MariaDB databases

How-to In the command line, go to the backup directory for MariaDB files.

To backup a database with a timestamp:

# mysqldump -u base_user -p base > base-dump_10092017.sql
Enter password:

To restore from a backup:

# mysql -u base_user -p base < base-dump_10092017.sql
Enter password: