Official MariaDB Docker Image: Persisting MySQL History
MariaDB is a popular open-source relational database management system (RDBMS), which is a community-developed branch of MySQL. Docker is a powerful platform for developing, shipping, and running applications inside containers. In this article, we will explore how to use the official MariaDB Docker image and persist the MySQL history for a more efficient development setup.
Prerequisites
To follow along with this article, you will need the following:
- Docker installed on your system
- Basic understanding of Docker and MariaDB
Getting Started with the Official MariaDB Docker Image
To start, you need to pull the official MariaDB Docker image from Docker Hub using the following command:
$ docker pull mariadb
After pulling the image, you can run a MariaDB container with the following command:
$ docker run --name my-mariadb -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb
This command creates a new container named my-mariadb with the root password set to my-secret-pw.
Persisting MySQL History
MySQL history is a record of all SQL queries executed in the MySQL client. By default, MySQL history is stored in the ~/.mysql_history file on the host system. However, when using a Docker container, this file is not persisted between container restarts.
To persist the MySQL history, you can mount a volume to the container that maps the ~/.mysql_history file inside the container to a file on the host system. You can do this using the following command:
$ docker run --name my-mariadb -e MYSQL_ROOT_PASSWORD=my-secret-pw -v ~/.mysql_history:/root/.mysql_history -d mariadb
This command maps the ~/.mysql_history file on the host system to the /root/.mysql_history file inside the container. Now, every SQL query executed in the MySQL client will be stored in the ~/.mysql_history file on the host system, even after the container is restarted.
Accessing the MySQL Client
To access the MySQL client, you can use the following command:
$ docker exec -it my-mariadb mysql -u root -p
This command opens an interactive MySQL session with the root user. You will be prompted to enter the root password, which you set when creating the container.
In this article, we explored how to use the official MariaDB Docker image and persist the MySQL history for a more efficient development setup. We covered the following key concepts:
- Pulling the official MariaDB Docker image
- Running a MariaDB container
- Persisting MySQL history using a mounted volume
- Accessing the MySQL client