Mathieu's blog

Install a Maria DB instance with Docker

Quick instructions to set up a Maria DB instance.

Install and run

Retrieve the Docker image using

sudo docker pull mariadb

Start the docker image my mounting a local directory to where the datbase will be stored to the /var/lib/mysql directory.

sudo docker run --name mariadb-container -e MARIADB_ROOT_PASSWORD=my_very_complicated_password -p 3306:3306 -v ~/mysql:/var/lib/mysql -d mariadb:latest

For more detailed instructions, look at this tutorial.

Add tables and users

To connect as root to the database, tap into the Docker image

sudo docker exec -it  mariadb-container /bin/bash

and call mariadb --password.

Start with creating a database. Call the CREATE_DATABASE method as explained here. After creating the database mydb, switch to this database by typing

use mydb

Create a table following the examples in this page.

Create users and grant privileges using

CREATE USER tintin IDENTIFIED BY 'my_password';
GRANT ALL ON `mydb`.* TO tintin;

See more examples here.

Local client

To test the database, you can install this client in ubuntu:

sudo apt install mariadb-client

and test your connection for the newly created user with

mariadb --user tintin --password --port 3306