You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
See here : Setting up multiple mysql users without storing passwords #213
I'm having difficulties applying the advices of the topic above. I'm reposting my problem because the issue is closed and has no visibility, here is my Dockerfile :
FROM mysql:5.7
ADD docker/mysql/script.sql /docker-entrypoint-initdb.d/script.sql
ADD docker/mysql/init_script_database.sh /docker-entrypoint-initdb.d/init_script_database.sh
RUN chmod -R 775 /docker-entrypoint-initdb.d
Here is my init_script_database.sh :
mysql --protocol=socket -uroot -p$MYSQL_ROOT_PASSWORD <<EOSQL
CREATE USER 'myuser_bis'@'%' IDENTIFIED WITH mysql_native_password AS '$MYSQL_SECOND_PASSWORD';GRANT USAGE ON *.* TO 'myuser_bis'@'%' REQUIRE NONE WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;
CREATE DATABASE IF NOT EXISTS `myuser_bis`;
GRANT ALL PRIVILEGES ON `myuser\_bis`.* TO 'myuser_bis'@'%';
EOSQL
Here is my docker-compose :
[...]
# MySQL container
mysql:
build:
context: ../
dockerfile: ./docker/mysql/Dockerfile
volumes:
# Prevent mysql data to be erased on restart
- mysql_volume:/var/lib/mysql
# Connect to "mysql_network" network, as defined below
networks:
- mysql_network
# Pass a list of environment variables to the container
environment:
TZ: "Europe/Rome"
MYSQL_ALLOW_EMPTY_PASSWORD: "no"
MYSQL_ROOT_PASSWORD: "${MYSQL_ROOT_PASSWORD}"
MYSQL_USER: "myuser"
MYSQL_PASSWORD: "${MYSQL_PASSWORD}"
MYSQL_DATABASE: "mybase"
MYSQL_SECOND_PASSWORD: "${MYSQL_SECOND_PASSWORD}"
command: [
'mysqld',
'--character-set-server=utf8mb4',
'--collation-server=utf8mb4_general_ci',
'--innodb-use-native-aio=0' # this has been added to prevent bugs mysqli::real_connect(): php_network_getaddresses: getaddrinfo failed
]
[...]
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).
If I comment the line "ADD docker/mysql/init_script_database.sh /docker-entrypoint-initdb.d/init_script_database.sh" from my Dockerfile, I'll will get "mybase" database filled with the sql script I provided, and "myuser" user.
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)
The text was updated successfully, but these errors were encountered:
When a container is started for the first time, a new database with the specified name will be created and initialized with the provided configuration variables. Furthermore, it will execute files with extensions .sh, .sql and .sql.gz that are found in /docker-entrypoint-initdb.d.
So if your volume was already initialized from a previous docker-compose up then it will be unchanged. You must first delete the volume (back up any important data first) and start again. (See also, docker-library/postgres#203 (comment))
See here : Setting up multiple mysql users without storing passwords #213
I'm having difficulties applying the advices of the topic above. I'm reposting my problem because the issue is closed and has no visibility, 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).
If I comment the line "ADD docker/mysql/init_script_database.sh /docker-entrypoint-initdb.d/init_script_database.sh" from my Dockerfile, I'll will get "mybase" database filled with the sql script I provided, and "myuser" user.
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)
The text was updated successfully, but these errors were encountered: