The other container would need to be using the same network, which means it needs to be in the same docker-compose file. Add your separate container to a docker-compose.override.yml file (do NOT edit Mailcow’s docker-compose.yml) and attach it to the mailcow-network (see how Mailcow’s containers in docker-compose.yml do it).
Once you do that, you just need to use mysql as the hostname. When Docker containers are on the same custom network, they can access each other by name.