Running tests in parallel using MariaDB in a Docker container

During local development I have a Docker container running MariaDB and I run Django on the host computer, macOS. This works and I can run tests successfully. But if I add the --parallel flag when running tests I run into problems.

First I had to brew install mysql-client which was needed to get mysqldump working.

But now I’ve run into errors with authentication which I’m stumped by, given that the non-parallel tests can successfully create and destroy a test database:

$ source .env && ./manage.py test --settings=myproject.settings.tests --parallel
Found 46 test(s).
Creating test database for alias 'default'...
Cloning test database for alias 'default'...
ERROR 1045 (28000): Access denied for user 'dbuser'@'localhost' (using password: YES)
mysqldump: Got error: 1045: Access denied for user 'dbuser'@'localhost' (using password: YES) when trying to connect

My docker-compose.yml is:

services:
  db:
    container_name: myproject_db
    env_file: .env
    image: mariadb:10.6.17
    ports:
      - 5556:3306
    restart: unless-stopped
    volumes:
      - ./docker/db/init:/docker-entrypoint-initdb.d
      - mysql_data:/var/lib/mysql

volumes:
  mysql_data:

.env is

# For use in Django:
export DATABASE_URL='mysql://dbuser:dbpw@localhost:5556/myproject'

# For use in Docker:
export MYSQL_USER=dbuser
export MYSQL_PASSWORD=dbpw
export MYSQL_DB=myproject

And my settings include:

DATABASES = {"default": dj_database_url.config()}
DATABASES["default"]["ENGINE"] = "django.db.backends.mysql"

I’ve fixed the “Access denied for user ‘dbuser’@‘localhost’…” error by changing the hostname used for the database from localhost to 127.0.0.1.

Now, mysqldump generates this error: mysqldump: Couldn't execute 'SELECT LIBRARY_NAME FROM INFORMATION_SCHEMA.LIBRARIES WHERE LIBRARY_SCHEMA = 'test_myproject' ORDER BY LIBRARY_NAME': Unknown table 'LIBRARIES' in information_schema (1109)

By seeing what arguments Django passes to the mysqldump command (which happens here in Django’s code), and then experimenting with running the command manually, it’s the --routines flag which causes this error to occur.

But I’m not sure what to do about fixing that.

Progress… I uninstalled mysql-client and installed mariadb:

brew uninstall mysql-client
brew install mariadb

Now, finally, the Django tests run in parallell.

I do get two warnings for each database cloning:

Cloning test database for alias 'default'...
WARNING: option --ssl-verify-server-cert is disabled, because of an insecure passwordless login.
WARNING: option --ssl-verify-server-cert is disabled, because of an insecure passwordless login.

But I’m not clear if this is an actual problem or not, other than being annoying.

Maybe if there was a Mac version of mariadb-dump I could install that (maybe aliased to mysqldump?) and that would work, without having to install mariadb?