Unknown MySQL server host 'db' error when using docker-compose

## What to do

1. Check database services configs in docker-compose.yml, make sure there is no error
2. Check database service logs, find out what cause the error.

## What I encountered

At first, I used mysql 8 to setup the docker-compose environment, then downgraded it to 5.7, but both used the same volume, which caused the error.

In the database logs, it says:
> [ERROR] [FATAL] InnoDB: Table flags are 0 in the data dictionary but the flags in file ./ibdata1 are 0x4800!

Googled the error message, it turns out I should delete the previous mysql storages.
(ref: https://stackoverflow.com/questions/50469060/mysqld-service-wont-start)

The solution to this situation is to purge the volume when executing docker-compose down.
(ref: https://stackoverflow.com/questions/45511956/remove-a-named-volume-with-docker-compose)

After run:
```
docker-compose down -v
```
then up the services, the database connection error has been fixed.

この記事が気に入ったらサポートをしてみませんか?