Is there a built-in way to get "CREATE DATABASE app;" and app user created?

In a standard docker MySQL image there are options to get app user and database automatically when creating a MySQL instance for the first time.

For example:
https://hub.docker.com/_/mysql

MYSQL_DATABASE
MYSQL_USER
MYSQL_PASSWORD

Init script creates database for app without manual actions required.


If I’m right, when creating a new PXC cluster all yamls can be applied in one go, if app user/database-name/password would be in deploy/secrets.yaml and these details picked up to:

CREATE DATABASE app;
CREATE USER …
GRANT ALL ON …
FLUSH PRIVILEGES;

… and app should be able to start using a new DB without manual steps

(just interested to think on what is missing to get a cluster in one button click)

Obviously, this can be easily done in an additional container, if this automation is not offered for now.

1 Like

Anyway, I have this in my CI/CD pipeline to solve it:

echo "Create app database"
rootpw=`kubectl get secret -n $namespace $secrets_resource_name -o json | jq -r '.data.root' | base64 --decode`
apppw=`kubectl get secret -n $namespace $secrets_resource_name -o json | jq -r '.data.app' | base64 --decode`

kubectl exec -it ${sts_pxc}-0 -n $namespace -- mysql -h${sts_haproxy} -uroot -p$rootpw -e "CREATE DATABASE IF NOT EXISTS app; CREATE USER IF NOT EXISTS \"app\"@\"%\" IDENTIFIED BY \"$apppw\"; GRANT ALL ON app.* TO \"app\"@\"%\"; FLUSH PRIVILEGES; SHOW DATABASES;"

So please feel free to close an issue.

2 Likes

Hello @Laimis ,

we have this feature in our roadmap. But it is not high priority because it can be easily solved with CICD or other automation tools.

1 Like

Cool. No worries and thanks for input. I have already proved that this xtradb solution is capable to be deployed/provisioned in “one click”.

1 Like

Hi @Laimis
If you need to init something bigger than empty the database - you can start a new cluster, manually put all required schemas and data and make a backup after all.
The next time when you need to create a new instance of the database with the same data - you can recover from backup immediately after empty cluster creation.

1 Like

Thanks. This is another option.

1 Like