MariaDB doesn’t create configuration files when sharing a directory using volumes

Alright I got it working! Here’s what happened.

I tried setting…
user 0 (named root on both, host and container) for the directory on my host
user 999 (named lxd on host and mysql on container) for the directory on my host
Both didn’t work.

I saw that there was a message “Switching to dedicated user ‘mysql’”, so I thought changing the user to root would allow to bypass these permission barriers,
so inside my.cnf, under [mysqld] I added user = root, so it looked like

[mysqld]

user = root

but that didn’t work also.

Later I learned that by accident (Confirmed thanks to https://unix.stackexchange.com/a/303503/264280) that you can’t use commands like cd to get into a directory that doesn’t allow execute (x) permission for your user.
So I allowed it for each class, but that didn’t work.

After that I also found out that MariaDB automatically changes user to mysql if the user that executed the entrypoint was root. Which can be found here.
First I thought to remove that check, but then I thought about changing the user which would be easier and work as intended.

And it finally worked!
Changing all permissions for a directory using chmod to 777 (rwxrwxrwx).
Changing the owner user and group to a custom one using chown user:group -R ./directory.
Setting --user user:group option in a docker run command.
Last two mentioned above were suggested by this article, which mentioned my exact issue.

I need to confirm it and experiment with it.
I really don’t want to give all permissions to a folder and I want do other things a bit differently,
but at least a file permission (code: 13) error disappeared when binding /var/lib/mysql like mentioned here.