0

Testing a new installation of SilverStripe on Linux (Ubuntu 20.04). My DB Container is set up like this:

...
services:
  db:
    image: mariadb:10
    env_file:
      - .env
    environment:
      MYSQL_ROOT_PASSWORD: ${SS_DATABASE_PASSWORD}
      MYSQL_PASSWORD: ${SS_DATABASE_PASSWORD}
      MYSQL_USER: ${SS_DATABASE_USERNAME}
      MYSQL_DATABASE: ${SS_DATABASE_NAME}
      MYSQL_TCP_PORT: ${SS_DATABASE_PORT}
      MYSQL_INITDB_SKIP_TZINFO: 0
...

and I have no issues connecting to the container directly. However, when I run my server with something like php -S localhost:8000, I get the access denied warning:

[Warning] mysqli::real_connect(): (HY000/1045): Access denied for user '<MYSQL_USER>'@'localhost' (using password: YES)

Trying to figure out what is not set properly.

1 Answers1

0

One of your environment variables is blank:

  • SS_DATABASE_NAME
  • SS_DATABASE_USERNAME
  • SS_DATABASE_PASSWORD

This would cause the user not to be created.

Also "boolean" variables are blank vs non-blank, so MYSQL_INITDB_SKIP_TZINFO: 0 is effectively a "true", meaning skip the tz initialization.

MYSQL_TCP_PORT isn't a variable considered by the mariadb container. Use command: --port $SS_DATABASE_PORT if you wish to change this.

danblack
  • 12,130
  • 2
  • 22
  • 41
  • Thanks for your reply. However, this doesn't seem to be the issue as all three variables you mentioned have values and I can confirm that by successfully accessing the database using the username and password via terminal. – Faith Baghan Jul 05 '22 at 09:53
  • Ah, is probably the php -S not running the the same filesystem and its trying to find the unix socket to connect to. Ideally your script should connect to the TCP port, and the exposed port on the container. I suspect you've got a mysql/mariadb server running outside the container without those authentication created in the container which is where the access denied is coming from. – danblack Jul 06 '22 at 03:01