Answer the question
In order to leave comments, you need to log in
How to create database from dump during container build?
Good day.
I ran into a problem that I can not create a database and import data from the dump into it.
Here is the Dockerfile
FROM mysql:5.7
ARG MYSQL_DATABASE
ARG MYSQL_USER
ARG MYSQL_PASSWORD
ARG MYSQL_ROOT_PASSWORD
# Create Database
RUN mkdir /usr/sql
RUN chmod 644 /usr/sql
COPY dump.sql /usr/sql/dump.sql
COPY mysql.cnf /etc/mysql/conf.d/mysql.cnf
#Create database
RUN /etc/init.d/mysql start && \
sleep 5 && \
mysql -u root -p${MYSQL_ROOT_PASSWORD} -e "CREATE DATABASE ${MYSQL_DATABASE}" && \
mysql -u root -p${MYSQL_ROOT_PASSWORD} -e "CREATE USER '${MYSQL_USER}'@'localhost' IDENTIFIED BY '${MYSQL_PASSWORD}'" && \
mysql -u root -p${MYSQL_ROOT_PASSWORD} -e "GRANT ALL PRIVILEGES ON * . * TO '${MYSQL_USER}'@'localhost';" && \
mysql -u root -p${MYSQL_ROOT_PASSWORD} -e "FLUSH PRIVILEGES" && \
mysql -u root -p${MYSQL_ROOT_PASSWORD} ${MYSQL_DATABASE} < /usr/sql/dump.sql
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question