This file will teach you how to setup a mariaDB docker container, import a .sql
dump and visualize it.
First create a compose.yml
file with the following info:
# Use root/example as user/password credentials
version: '3.1'
services:
db:
image: mariadb
restart: always
environment:
- MARIADB_USER=example-user
- MARIADB_PASSWORD=my_cool_secret
- MARIADB_ROOT_PASSWORD=my-secret-pw
volumes:
- ./mariadb:/var/lib/mysql
adminer: # Visualizer
image: adminer
restart: always
ports:
- 8080:8080
THIS FILE IS NOT SECURE, DO NOT OPEN ANY PORTS TO THE OUTSIDE WORLD
Now run the compose file using docker-compose up -d
or docker compose up -d
depending on which utility you have installed. This will build the files and create a folder called /mariadb
in your CWD with all the files for the install.
Once the setup is done running copy your .sql
file into /mariadb
. There are then 2 options to choose from to open a terminal in the container (pick either one):
-
Docker desktop; If you have it installed head to docker desktop, go to containers and find the mariadb container. Hit the terminal icon to open a terminal in the container.
-
Docker exec; Run
docker ps
, and find the mariabd image in the table. Copy the container ID and rundocker exec -it <CONTAINER ID> bash
.
Regardless of which you picked run cd /var/lib/mysql
to get to the correct folder for step 3!
Your .sql
file will be in /var/lib/mysql
which we just navigated to. First we need to create a database, then we can import it.
Create a database by running mysql -u root -p
, it will ask for a password, which is the MARIADB_ROOT_PASSWORD
we set earlier (my-secret-pw
if you never changed it).
Once you have entered the password run CREATE DATABASE <DATABASE NAME>;
where <DATABASE NAME>
is the name you want for the imported DB.
so you can now import it with mysql -u root -p <DATABASE NAME> < <FILENAME>.sql
again it will prompt you for the root password which will be MARIADB_ROOT_PASSWORD
(my-secret-pw
if you never changed it).
Now you can go to localhost:8080 and login with:
System: MySQL
Server: db
Username: root
Password: <MARIADB_ROOT_PASSWORD> (`my-secret-pw` if you never changed it)
Database: <DATABASE NAME>
This will let you visualize all your tables in one place!