OK, we all know that there are a ton of database options out there these days. , , . And that’s really just the tip of the iceberg. Choosing a new database is likely one of the most important architectural decisions that go into creating or integrating into a new solution or application.
The reasons for choosing a database can be everything from extremely simple to pretty damn complex, but, ultimately, it all boils down to the type of data workload you’re looking to handle. But that’s not something I’m going to get into, because that’s the kind of research you can certainly go off and do on your own.
Instead, in this article, I want to focus on the quickest way you can go from nothing to having a local instance of a database up, running and ready to use so you can start checking things out, using a , for yourself.
OK, let’s get into it.
Step 1 - Install Docker
Now, unless you’ve been living under a rock for the past several years I'm willing to bet you’ve at least heard of , or, at the very least, the concept of containerization. And, if not, no biggie check out if you’re curious.
Either way, the good news is that using
Step 2 - Start a MariaDB Docker Container
Once you’ve successfully installed Docker on your machine, you’re ready to pull the MariaDB image and spin up a container (which will contain a MariaDB database instance).
For this, you’re going to use the hosted at .
Open up a new terminal window and execute the following command.
$ docker run -p 127.0.0.1:3306:3306 --name mdb -e MARIADB_ROOT_PASSWORD=Password123! -d mariadb:latest
The previous statement will pull down the latest version of the Official MariaDB image and spin up a new container on localhost (127.0.0.1
), exposing port 3306
and allow you to connect using the root user
with password Password123!
.
Hint: I guess this is something like Step 2-b, but you can confirm that the docker run command has successfully pulled the MariaDB Image and spun up a container by executing docker ps
, which will show you all of the containers currently running.
Step 3 - Connect to MariaDB
Lastly, you don’t need to install anything else to start using MariaDB. While you certainly can use other types of clients or tools to connect to and communicate with a MariaDB database, for this brief walkthrough you don't have to worry about any of that. Everything you need you already have. Just use the mariadb
command-line client that’s included within the MariaDB Docker container.
Execute the following to connect to MariaDB using the command-line client.
$ docker exec -it mdb mariadb --user root -p Password123!
Which should result in something like the following:
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 4 Server version: 10.6.3-MariaDB-1:10.6.3+maria~focal mariadb.org binary 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)]>
And that’s it! That’s all you need to connect to and start using (querying) MariaDB.
Happy coding, friends!
First Published