Reputation: 15151
I created a docker-compose.yml
.
version: "3.7"
services:
db:
container_name: mysql
image: mysql
ports:
- 3306:3306
volumes:
- ./sql:/docker-entrypoint-initdb.d
- ./mysql:/var/lib/mysql
environment:
MYSQL_ROOT_USER : root
MYSQL_ROOT_PASSWORD: root_pass
MYSQL_DATABASE: wp1
MYSQL_USER: wp
MYSQL_PASSWORD: pass
restart: always
And in sql
directory, I put a init.sql
.
CREATE DATABASE IF NOT EXISTS wp2;
Then run docker-compose up
.
In the log there is a entry for the init script.
mysql | 2020-04-08 02:17:32+00:00 [Note] [Entrypoint]: /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/init.sql
But the database wp2
is not created.
$ docker exec -it mysql bash
# mysql -u wp -ppass
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| wp1 |
+--------------------+
How can I create a database with mysql container init script?
Upvotes: 0
Views: 2021
Reputation: 14666
Your wp
user doesn't have access rights on wp2.
Append to your sql file:
GRANT ALL on wp2.* to wp@'%';
Upvotes: 1