How to connect to mysql through the docker network?

I am using docker compose for my homeassistant and mysql container:

networks:
  internal:
    driver: bridge
    name: internal

services:
  ha-test:
    image: ghcr.io/home-assistant/home-assistant:stable
    container_name: ha-test
    restart: unless-stopped
    networks:
      - internal
    environment:
      - TZ=Europe/Berlin
    volumes:
      - ${CONFIG_PATH}/ha-test:/config
      - /run/dbus:/run/dbus:ro
    ports:
      - 7123:8123

  
  db:
    image: mysql:latest
    container_name: mysql
    restart: unless-stopped
    networks:
      - internal
    environment:
      - MYSQL_ROOT_PASSWORD=${ROOT_PASS}
      - MYSQL_DATABASE=homeassistant
      - MYSQL_USER=ha
      - MYSQL_PASSWORD=changeme

I also tried using the entrypoint to create the database:

    entrypoint:
      sh -c "
        echo 'CREATE DATABASE IF NOT EXISTS homeassistant; \
              CREATE USER IF NOT EXISTS 'ha'@'%' IDENTIFIED BY 'changeme'; \
              GRANT ALL PRIVILEGES ON homeassistant.* TO 'ha'@'%'; \
              FLUSH PRIVILEGES;' > /docker-entrypoint-initdb.d/init.sql;
        /usr/local/bin/docker-entrypoint.sh --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
      "

My configuration.yaml looks like:

recorder:
  db_url: mysql://ha:changeme@mysql/homeassistant?charset=utf8mb4

Still when starting homeassistant the logs always show:

sqlalchemy.exc.OperationalError: (MySQLdb.OperationalError) (1045, "Access denied for user 'ha'@'172.18.0.3' (using password: YES)")
(Background on this error at: https://sqlalche.me/e/20/e3q8)

I am able to log in into the database from inside the mysql container.

What am I doing wrong?
Thanks in advance.