You don’t have MySQL installed to test this example? No problem, one option is to use Docker to run it.
docker pull mysql:8.0
docker run -d -p 3306:3306 \
--name mysql-docker-container \
-e MYSQL_DATABASE=YNaMi \
-e MYSQL_USER=crazy \
-e MYSQL_PASSWORD=crazy \
-e MYSQL_ROOT_PASSWORD=root \
mysql:8.0
By the way, if you didn’t pull the docker image explicitly by running the docker pull mysql:8.0
command, nothing
to worry about as the docker run
command will pull the image if it’s not found locally.
docker run
command first creates a writeable container layer over the specified image i.e. mysql:8.0
and then starts it using the specified command.-d
prints the container ID and runs the container in the background.-p
publishes/exposes a container’s port(s) to the host.–name
sets the name of the container i.e. mysql-docker-container
.-e
sets environment variables:
MYSQL_USER=crazy
has been setMYSQL_PASSWORD=crazy
has been setMYSQL_DATABASE=YNaMi
has been setMYSQL_ROOT_PASSWORD=root
has been setRun the docker exec
command in order to connect to the mysql-docker-container
docker container:
docker exec -it mysql-docker-container bash
mysql-docker-container
through -it
that tells Docker
to allot a pseudo-TTY
connected to the container’s stdin
.mysql -u root -p
command to invoke MySQL
with the root
user
docker run
command (i.e. root
in our case).mysql -u crazy -p
command to invoke MySQL
with the crazy
user
docker run
command (i.e. crazy
in our case).show databases;
That’s it, we have up and running MySQL
container happily :)
Simplest solution given below but there are others like using NFS:
The delegated configuration provides the weakest set of guarantees. For directories mounted with delegated the container’s view of the file system is authoritative, and writes performed by containers may not be immediately reflected on the host file system. In situations such as NFS asynchronous mode, if a running container with a delegated bind mount crashes, then writes may be lost.
The cached configuration provides all the guarantees of the delegated configuration, and some additional guarantees around the visibility of writes performed by containers. As such, cached typically improves the performance of read-heavy workloads, at the cost of some temporary inconsistency between the host and the container.
Ok, we can use them simply as volume option, for example:
my-delegated-volume:/var/volume2:delegated
my-cached-volume:/var/volume1:cached