Database Password other than default results in an error

Version

5.11.7-d

Environment

Docker (dockerfiles/debian)

Describe the bug

Hi,
it’s my first time trying to install InvoiceNinja on an Ubuntu Host in Docker.
When I use the default config of password ninja for user ninja everything works and I can use InvoiceNinja just fine:

DB_PASSWORD=ninja
MYSQL_PASSWORD=ninja

But as soon as I change the password to a custom one (keeping both db and mysql password the same), I get this error:

app-1    |   SQLSTATE[HY000] [1045] Access denied for user 'ninja'@'172.18.0.4' (using p
app-1    |   assword: YES) (Connection: mysql, SQL: select exists (select 1 from informa
app-1    |   tion_schema.tables where table_schema = 'ninja' and table_name = 'migration
app-1    |   s' and table_type in ('BASE TABLE', 'SYSTEM VERSIONED')) as `exists`)

Steps To Reproduce

  1. git clone GitHub - invoiceninja/dockerfiles: Docker files for Invoice Ninja -b debian
  2. cd dockerfiles/debian
  3. Change the DB_ROOT_PASSWORD, DB_PASSWORD, MYSQL_PASSWORD and MYSQL_ROOT_PASSWORD to two custom but different passwords
  4. docker compose up (I changed the passwords before the first start)

Expected Behavior

If I understood correctly, invoiceninja is creating the db and all the accounts with correct passwords. This does not seem to be the case.

Logs

app-1    | In Connection.php line 825:
app-1    |
app-1    |   SQLSTATE[HY000] [1045] Access denied for user 'ninja'@'172.18.0.4' (using p
app-1    |   assword: YES) (Connection: mysql, SQL: select exists (select 1 from informa
app-1    |   tion_schema.tables where table_schema = 'ninja' and table_name = 'migration
app-1    |   s' and table_type in ('BASE TABLE', 'SYSTEM VERSIONED')) as `exists`)
app-1    |
app-1    |
app-1    | In Connector.php line 66:
app-1    |
app-1    |   SQLSTATE[HY000] [1045] Access denied for user 'ninja'@'172.18.0.4' (using p
app-1    |   assword: YES)
app-1    |

Thank you very much for your help.

Hi,

Is it possible the password includes a #

Hi, thanks for the quick reply.

Sadly the password does not contain a #. I even tried 12345678 for the ninja user and 123456789 for the root user.

This is the complete env file:

# IN application vars
APP_URL=http://<my_ip_in_vpn>
APP_KEY=base64:<redacted>
APP_ENV=production
APP_DEBUG=true
REQUIRE_HTTPS=false
PHANTOMJS_PDF_GENERATION=false
PDF_GENERATOR=snappdf
TRUSTED_PROXIES='*'


CACHE_DRIVER=redis
QUEUE_CONNECTION=redis
SESSION_DRIVER=redis

REDIS_HOST=redis
REDIS_PASSWORD=null
REDIS_PORT=6379

FILESYSTEM_DISK=debian_docker

# DB connection
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=ninja
DB_USERNAME=ninja
DB_PASSWORD=12345678
DB_ROOT_PASSWORD=123456789
DB_CONNECTION=mysql

# Create initial user
# Default to these values if empty
[email protected]
IN_PASSWORD=changeme!
# IN_USER_EMAIL=
# IN_PASSWORD=

# Mail options
MAIL_MAILER=log
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null
MAIL_FROM_ADDRESS='[email protected]'
MAIL_FROM_NAME='Self Hosted User'

# MySQL
MYSQL_ROOT_PASSWORD=123456789
MYSQL_USER=ninja
MYSQL_PASSWORD=12345678
MYSQL_DATABASE=ninja

# GoCardless/Nordigen API key for banking integration
NORDIGEN_SECRET_ID=
NORDIGEN_SECRET_KEY=

IS_DOCKER=true
SCOUT_DRIVER=null
SNAPPDF_CHROMIUM_PATH=/usr/bin/google-chrome-stable

Still, I get the Access denied for user ... error.

Maybe this will help:

Sadly this also didn’t help.

The storage:link command fails with the message ERROR The [public/storage] link already exists., so I think the storage link is already ok. The other .env variables didn’t change the error.

It may help to run docker compose up -d

After every change I run

docker compose down
docker compose up -d

That should be enough right?

@david do you have any suggestions, it looks like a few users are running into the same problem.

I believe that when you start the container for the first time, if the database db container has not been created yet, then the db credentials set at that point in time will be used to create the root db user and db user.

If you later change them to another value, that will not change anything. You will want to remove the database image completely. Set your preferred db credentials. And then start up the containers again.

1 Like

Thanks for your response.

I tried to provide a minimal environment on labs.play-with-docker.com where I could replicate the error. But there the issue didn’t exist :wink:

I needed to run all these commands to use the custom password. It seems as there was still some DB config that was being used:

docker compose down --volumes --remove-orphans
rm -rf ./.env ./nginx ./php ./supervisor
docker image prune -a
docker system prune -a --volumes
docker network rm `docker network ls -q`
cd ..
rm -rf dockerfiles/
1 Like

Glad to hear it, thanks for sharing the solution!