Why we have 2 database sections in the ENV file for docker

Hi,

I already have mysql running in a separate container locally. I created a new database name invoiceninja in it and then setup the env file as:

# DB connection
DB_HOST=192.168.2.10
DB_PORT=33076
DB_DATABASE=invoiceninja
DB_USERNAME=ninja
DB_PASSWORD=mypass

I can see another section in the env file:

# MySQL
MYSQL_ROOT_PASSWORD=ninjaAdm1nPassword
MYSQL_USER=ninja
MYSQL_PASSWORD=ninja
MYSQL_DATABASE=ninja

what’s it for? I think it should just use the existing database???

Hi,

I’ve searched the codebase, the MYSQL_ params seem to be used for the automated tests.

https://github.com/search?q=repo%3Ainvoiceninja%2Finvoiceninja%20MYSQL_ROOT_PASSWORD&type=code

Hi,

thanks but is this something I must setup? I thought it just needs a database and once you’ve supplied the database connection details, it should create it’s own tables etc.?

I don’t think you need to provide those values.

ok why am I getting the following error:

SQLSTATE[HY000] [1045] Access denied for user 'ninja'@'10.42.0.1' (using pa
ssword: YES) (Connection: mysql, SQL: select table_name as `name`, (data_le
ngth + index_length) as `size`, table_comment as `comment`, engine as `engi
ne`, table_collation as `collation` from information_schema.tables where ta
ble_schema = 'invoiceninja' and table_type = 'BASE TABLE' order by table_na
me)
In Connector.php line 65:
SQLSTATE[HY000] [1045] Access denied for user 'ninja'@'10.42.0.1' (using pa
ssword: YES)

mysql database is not running at 10.42.0.1. I have specified it to be running on a different IP i.e. 192.168.2.10

@david can you please advise?

I supplied the following environment variables:

-e APP_ENV='production' \
  -e APP_DEBUG=0 \
  -e APP_URL='http://ninja.dev' \
  -e APP_KEY='base64:my_key' \
  -e APP_CIPHER='AES-256-CBC' \
  -e DB_TYPE='mysql' \
  -e DB_STRICT='false' \
  -e DB_HOST='192.168.2.10:3102' \
  -e DB_DATABASE='ninja' \
  -e DB_USERNAME='ninja' \
  -e DB_PASSWORD='ninja' \
  -e REQUIRE_HTTPS='true' \
  -e TRUSTED_PROXIES='my proxy ip address here'

you’re sure you created ‘ninja’ user and password with permissions to the ninja db in your db container? sometimes people forget this

yes,

I can login using ninja, with password ninja and can see the database ninja. I even created a test table to make sure user ninja had appropriate permissions to create tables in this database.

I don’t understand why we have to supply mysql and database options twice in the env file.
Once you have the database connection details with username/password/database name then it should be enough to create any database tables within that database?

btw I tested with both mysql and without mysql details. still get the same error.

I never had to supply the DB details twice in .env, only once and I’ve installed invoiceninja a dozen times…
The access denied error is likely that you restricted the ninja db user to only localhost or only a specific IP, please recreate the user with allowing access from all so you can test the connection from invoiceninja