TL;DR go to Setup Database to start the database
- Mysql setup on Docker is convenient because it is easy to switch through different Mysql versions or even have different Mysql containers with different versions
- It is also good becaue it takes care of all the instalations and all we need to do is specify the version via tag, e.g.
mysql:8.0.32 - It is easy to configure Mysql through
docker-compose.yaml. We can specify the database, user, password, port. - Docker also allows to have database initialization scripts that are run when the database is created. This can be very convenient when developing various applications using databases. In this case the scripts are in the
initdbfolder. They are run in alphabetical order and should not have any SQL syntax errors.
- Setup Docker and Docker Compose
- Docker https://docs.docker.com/get-docker/
- Docker Compose https://docs.docker.com/compose/install/
- Start database
docker-compose up
Because we have a volume specified and have it bound to /var/lib/mysql, the Mysql data is persisted even if our containers go down or are removed. To fully restart the database and remove its current data, we need to delete the volume. We need to delete the volume also if we want for Docker to run the initialization scripts with the next run as well.
docker volume ls
DRIVER VOLUME NAME
local mysql_mysql-data- Stop docker containers
docker-compose down - Search for the correct volume
docker volume list - Delete the volume
docker volume rm mysql_mysql-data - Run
docker-compose upto start the stack - Check if the are no SQL errors
Adminer is a database client that we can use to connect to the database, look at the data, run commands. In this case it can be found via http://localhost:8080/. We can connect to it using
| Field | Value |
|---|---|
| System | MySQL |
| Server | docker-mysql |
| Username | root |
| Password | root |
| Database | test_db |