Initializing MySQL Database with Schema in Docker
When attempting to create a Docker container with a MySQL database and add a schema, you may encounter challenges in executing the desired commands successfully. Here's a comprehensive solution to resolve this issue:
mysqldump -h <your_mysql_host> -u <user_name> -p --no-data <schema_name> > schema.sql
FROM mysql:5.7.15 MAINTAINER me ENV MYSQL_DATABASE=<schema_name> \ MYSQL_ROOT_PASSWORD=<password> ADD schema.sql /docker-entrypoint-initdb.d EXPOSE 3306
The docker-entrypoint-initdb.d directory contains scripts that run during database initialization, including SQL files.
docker-compose build docker-compose up
By following these steps, you can effectively initialize a MySQL database with a schema within a Docker container.
The above is the detailed content of How to Initialize a MySQL Database with a Schema in Docker?. For more information, please follow other related articles on the PHP Chinese website!