简体   繁体   English

Docker 未将 SQL 文件导入 mysql

[英]Docker is not importing SQL files to mysql

It's hours that I'm trying to solve this problem...这是我试图解决这个问题的几个小时......

This is my docker-compose :这是我的docker-compose

#MySQL Service
db:
  image: mysql
  container_name: db
  restart: unless-stopped
  tty: true
  ports:
    - "3307:3306"
    - "8001:3306"
  environment:
    MYSQL_DATABASE: laravel
    MYSQL_ROOT_PASSWORD: your_mysql_root_password
    SERVICE_TAGS: dev
    SERVICE_NAME: mysql
  volumes:
    - ./database/dbdata:/var/lib/mysql/
    - ./config/mysql/my.cnf:/etc/mysql/my.cnf
    - ./database:/docker-entrypoint-initdb.d
  networks:
    - app-network

and this is my folder这是我的文件夹

.
├── docker-compose.yml
├── database
│   ├── 1-schema.sql
│   ├── 2-data.sql
│   ├── 3-user.sql
│   ├── dbdata
│   │   ├── #ib_16384_0.dblwr
│   │   ├── #ib_16384_1.dblwr
│   │   ├── #innodb_temp
│   │   ├── 4907efde64b2.pid
...

However, If i run但是,如果我跑

docker compose down
docker compose build
docker compose up

and log into the container, and run mysql , if I check the databases, there is not the one I'm importing..并登录到容器中,然后运行mysql ,如果我检查数据库,则没有我要导入的那个..

What am I missing?我错过了什么?

Turns out that if there is a volume mounted to persist the data (in my case /database/dbdata:/var/lib/mysql/ ) from a previous build, the SQL files will not be run, therefore you need to delete everything inside that folder, and restart the container事实证明,如果安装了一个卷来保存以前构建的数据(在我的情况下是/database/dbdata:/var/lib/mysql/ ),则 SQL 文件将不会运行,因此您需要删除里面的所有内容该文件夹,然后重新启动容器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM