I started a docker container with mysql.
Actually i want to create a new user and a new table - and i have to do it in the MySQL Workbench.
This ist my docker run command:
docker run -p 3306:3306 --name mysql-server -v ~/Development/web/myproject/docker/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=root -d mysql:latest
My Question is:
How can i add a sql startup script (only for the first start of the container) which creates my user and my table?
Which steps do i have to do?
Could some one help me here?
Thanks a lot!
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- Docker task in Azure devops won't accept "$(pw
- php PDO::FETCH_ASSOC doesnt detect select after ba
You need to create user via
MYSQL_USER
,MYSQL_PASSWORD
env vars and use volume/docker-entrypoint-initdb.d
to map directory with your startup scripts (.sh
,.sql
,.sql.gz
)Explanation from: https://hub.docker.com/_/mysql/
MYSQL_USER, MYSQL_PASSWORD
These variables are optional, used in conjunction to create a new user and to set that user's password. This user will be granted superuser permissions (see above) for the database specified by the
MYSQL_DATABASE
variable. Both variables are required for a user to be created.Initializing a fresh instance
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
. Files will be executed in alphabetical order. You can easily populate your mysql services by mounting a SQL dump into that directory and provide custom images with contributed data. SQL files will be imported by default to the database specified by theMYSQL_DATABASE
variable.