Question :
I am creating a docker mariadb image and wanted to create a database and user name before bootstrapping mysqld daemon. So as per the documentation I tried below queries.
mysql_embedded -e "CREATE DATABASE IF NOT EXISTS test ;"
mysql_embedded -e "CREATE USER admin@localhost IDENTIFIED BY 'password';"
mysql_embedded -e "select user, host, password, plugin from mysql.user;"
The above query successfully create a database and display user information. But it didn’t create the user i.e the middle query didn’t get executed. Even it didn’t show any error. Can’t I create an user using mysql_embedded
?
What is the alternative to mysql_embedded. Is it mysqld –bootstrap ?
Here is a blogpost on mysql_embedded https://mariadb.com/resources/blog/using-mysql_embedded-and-mysqld-bootstrap-to-tinker-with-privilege-tables/
Answer :
As you are using the docker mariadb image the best way is to set the environment variables when running the image:
- MYSQL_DATABASE
- MYSQL_USER
- MYSQL_PASSWORD
ref: https://hub.docker.com/_/mariadb/
These will case the database and user to be created with grants (ref)