The tutorial explain how to initialize mysql use dockerFile .
- DockerFile
FROM mysql:8
ADD setup.sql /docker-entrypoint-initdb.d/
RUN chown -R mysql:mysql /docker-entrypoint-initdb.d/
CMD [“mysqld”, “–character-set-server=utf8mb4”, “–collation-server=utf8mb4_unicode_ci”]docker-entrypoint-initdb.d:
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. - setup.sql
CREATE DATABASE testDB;
USE testDB;
CREATE TABLE users ( id bigint(20),name varchar(60));
CREATE TABLE user_roles (user_id bigint(20),role_id bigint(20));
CREATE TABLE roles ( id bigint(20),name varchar(60));
INSERT INTO roles(name) VALUES(‘ROLE_USER’);
INSERT INTO roles(name) VALUES(‘ROLE_ADMIN’);