You can simply avoid redefining the mysql in one of the two docker-compose.yml files and connect mysql and the other containers to the same network.
In order to do so, create a network:
docker network create shared
Assign your network to your mysql container:
version: '3'
services:
mysql:
...
networks:
- shared
networks:
shared:
external:
name: shared
For any other container that has need to access mysql, just add the same network definition as above:
version: '3'
services:
app1:
...
networks:
- shared
app2:
...
networks:
- shared
...
networks:
shared:
external:
name: shared
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…