0

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/

2
  • mysql_embedded isn't really there for creating users. embedded is when mysql is effectively a shared library for an application. I recommended creating the after bootstrap/mysql_install_db.
    – danblack
    Commented Jan 10, 2019 at 23:36
  • But from the --help option it seems we can execute any query.
    – SkyRar
    Commented Jan 10, 2019 at 23:38

1 Answer 1

0

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)

1
  • Sorry but I am not using official image. I am creating one from my own using Alpine. However its a general question related to Mariadb only. So let's leave about Docker.
    – SkyRar
    Commented Jan 10, 2019 at 23:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.