-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Setting up multiple mysql users without storing passwords #213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
You could put it into a shell script and have that interpret any environment variables for other passwords. Something like the following: #!/bin/bash
set -e
mysql --protocol=socket -uroot -p$MYSQL_ROOT_PASSWORD <<EOSQL
CREATE DATABASE mydb;
CREATE USER 'readuser'@'%' IDENTIFIED BY '$CUSTOM_PASS_1';
GRANT SELECT ON mydb.* TO 'readuser'@'%';
CREATE USER 'writeuser'@'%' IDENTIFIED BY '$CUSTOM_PASS_2';
GRANT INSERT, UPDATE, SELECT, DELETE ON mydb.* TO 'writeuser'@'%';
EOSQL
# I don't think anything needs to be escaped in this heredoc. Then just run it:
This will still expose the passwords to the environment of the container, but they won't be in your git repo. |
You could even use mysql --protocol=socket -uroot -p$MYSQL_ROOT_PASSWORD <<EOSQL
CREATE DATABASE mydb;
CREATE USER 'readuser'@'%' IDENTIFIED BY '${CUSTOM_PASS_1:-default-custom-pass-1}';
GRANT SELECT ON mydb.* TO 'readuser'@'%';
... |
read the thread and help me solve my own problem, thanks guys! |
I'm having difficulties applying the advices above, here is my Dockerfile :
Here is my init_script_database.sh :
Here is my docker-compose :
Finally I have env file with all the variables (properly read). While running docker-compose up, I get no errors. I get "mybase" database, "myuser" user, but the user "myuser_bis" is missing and its database too. Also, "mybase" database is empty (as if script.sql was not read). How can I make my shell script work in order to add my second user ? Thanks in advance for your help. (also I'm using compose-down and prune volumes each time to be sure I get a fresh start) |
I would like to set up MySQL with two users; writeuser and readuser. My Dockerfile and build context are committed to a public git repository. Currently I create the users like so:
Dockerfile
setup.sql
But this exposes passwords to anyone who can access the git repo. I would like to be able to pass passwords in as environment variables instead, but this isn't supported by the .sql script format.
What would be the best way of going about this?
The text was updated successfully, but these errors were encountered: