编程知识 cdmana.com

Docker initializes MySQL table creation statement

# 1.  establish Dockerfile file 

FROM mysql:5.7
WORKDIR /docker-entrypoint-initdb.d
COPY utf8mb4.cnf /etc/mysql/conf.d/utf8mb4.cnf
COPY ./sql/ /opt/sql/
ADD init.sql /docker-entrypoint-initdb.d/

# 2.  establish utf8mb4.cnf file ( Main configuration code and time zone )
[client] 
default-character-set = utf8mb4 
[mysql] 
default-character-set = utf8mb4 
[mysqld] 
character-set-client-handshake = FALSE 
character-set-server = utf8mb4 
collation-server = utf8mb4_unicode_ci 
init_connect=’SET NAMES utf8mb4’
default-time_zone = '+8:00'
# 3. ./sql Under the folder we need to initialize sql file 
createDatabase.sql  product.sql
# 4. init.sql To store our execution sql The order of 

source /opt/sql/createDatabase.sql;
use product;
source /opt/sql/product.sql;
# 5. init.sql Must be on  /docker-entrypoint-initdb.d Under the table of contents 
#  Default docker The script statement here will be initialized when starting , And it's only done once when the container is created 

 

版权声明
本文为[osc_ 08vvd847]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201225074802306L.html

Scroll to Top