Using environment variables to create user@localhost

Using docker-compose to spin up the latest MariaDB image/instance:

... environment: MARIADB_ROOT_PASSWORD: ${DATABASE_SA_PASSWORD} MARIADB_DATABASE: ${DATABASE_NAME} MARIADB_USER: ${DATABASE_USERNAME} MARIADB_PASSWORD: ${DATABASE_PASSWORD} ... This config works and creates user@% granted full access to the specified database with the specified password... but instead I need it to create user@localhost, either in addition to or instead of user@%. Otherwise I have to dig into using the docker entrypoint for the container to run a SQL script to create the user and would rather not have to do that.

Is what I am asking for possible?

Answer Answered by Daniel Black in this comment.

$ podman run --rm --env MARIADB_DATABASE=bob --env MARIADB_USER=roger --env MARIADB_PASSWORD=rabbit --env MARIADB_ROOT_PASSWORD=sudo -d --name m102 mariadb:10.2
81a43a5a4b317cd887b8b926b784e18147b3c3eee5d59fbca66915d6087a1beb

$ podman exec -ti m102 mysql -u roger -prabbit bob 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 10.2.44-MariaDB-1:10.2.44+maria~bionic mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [bob]> \s
--------------
mysql  Ver 15.1 Distrib 10.2.44-MariaDB, for debian-linux-gnu (x86_64) using readline 5.2

Connection id:		8
Current database:	bob
Current user:		roger@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server:			MariaDB
Server version:		10.2.44-MariaDB-1:10.2.44+maria~bionic mariadb.org binary distribution
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	latin1
Db     characterset:	latin1
Client characterset:	latin1
Conn.  characterset:	latin1
UNIX socket:		/var/run/mysqld/mysqld.sock
Uptime:			24 sec

Threads: 6  Questions: 6  Slow queries: 0  Opens: 18  Flush tables: 1  Open tables: 11  Queries per second avg: 0.250
--------------

MariaDB [bob]> select current_user();
+----------------+
| current_user() |
+----------------+
| roger@%        |
+----------------+
1 row in set (0.00 sec)

I'm not sure what you are missing out without a user@localhost as shown above a user @% user can log in on the unix socket.

The only way is to create other users is with SQL in /docker-entrypoint-initdb.d during startup like you suggested.

Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.