0

I have a docker compose file in which I create a MySQL container:

database:
  image: mysql:5.7
  command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci
  ports:
    - "3306:3306"
  expose:
    - "3306"
  restart: always
  environment:
    MYSQL_ROOT_PASSWORD: docker
  volumes:
    - ./data/${PROJECTNAME}/mysql:/var/lib/mysql
    - ./init:/docker-entrypoint-initdb.d

My SQL init script simply does the following:

CREATE DATABASE User;
CREATE DATABASE Application;

When the containers are setup, the data is stored in a data directory in my environment project for the relevant project, so for a project called "base2" the structure ends up looking like this:

enter image description here

I can connect to the databases fine, but I have encountered some issues which I'm not sure whether they relate to my docker-compose setup or something else. When I run:

DROP DATABASE Application;

CREATE DATABASE Application;

Throws an error: Can't create database 'Application'; database exists. I see similar errors when dropping and recreating tables too.

Another answer to someone asking a similar question states that the ibdata1, ib_logfile0 and ib_logfile1 need to be in the root mysql directory - in this case I can see those files are present so I wasn't able to resolve this when researching similar issues.

DannyXCII
  • 888
  • 4
  • 12

1 Answers1

0

Try giving permision like below to your local directory

sudo chown -R mysql:mysql ./data/${PROJECTNAME}/mysql

pravin deore
  • 91
  • 2
  • 10