前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >docker-compose安装mysql并指定忽略表名大小写以及挂载配置文件

docker-compose安装mysql并指定忽略表名大小写以及挂载配置文件

作者头像
阿超
发布2023-07-21 15:16:13
1.7K0
发布2023-07-21 15:16:13
举报
文章被收录于专栏:快乐阿超

1

之前写了docker-compose.yml安装mysql

但是发现其表名大小写敏感,也没指定配置文件,参考我之前写的:

mysql大小写踩坑

mysql8卸载重新安装并配置lower_case_table_names=1

mysql having报错this is incompatible with sql_mode=only_full_group_by

于是重新编写docker-compose.yml

代码语言:javascript
复制
# Use root/example as user/password credentials
version: '3.1'

services:

  db:
    image: mysql
    # NOTE: use of "mysql_native_password" is not recommended: https://dev.mysql.com/doc/refman/8.0/en/upgrading-from-previous-series.html#upgrade-caching-sha2-password
    # (this is just an example, not intended to be a production configuration)
    command: --default-authentication-plugin=mysql_native_password --lower_case_table_names=1
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: root
    ports:
      - 3306:3306
    volumes:
      - ./my.cnf:/etc/mysql/my.cnf

对应的my.cnf

代码语言:javascript
复制
[mysqld]
SQL_MODE=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
CHARACTER_SET_SERVER=utf8mb4

然后运行

代码语言:javascript
复制
achaodeMacBook-Pro:DockerCompose achao$ cd /Library/DockerCompose/
achaodeMacBook-Pro:DockerCompose achao$ docker-compose -f mysql-compose.yml up -d
[+] Running 12/12
 ✔ db 11 layers [⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿]      0B/0B      Pulled                      34.7s 
   ✔ 29e800056b7e Pull complete                                           11.7s 
   ✔ 69da292eb326 Pull complete                                           11.7s 
   ✔ 8850ef02dd58 Pull complete                                           11.7s 
   ✔ 86a76caa9e20 Pull complete                                           11.8s 
   ✔ 881324b10832 Pull complete                                           11.8s 
   ✔ 1f5d1a8fa489 Pull complete                                           11.8s 
   ✔ 5efbe9eacf59 Pull complete                                           25.7s 
   ✔ 80db22f26c0f Pull complete                                           25.7s 
   ✔ e5595b935c31 Pull complete                                           30.0s 
   ✔ c391d4efe159 Pull complete                                           30.0s 
   ✔ e5527cf2eb5f Pull complete                                           30.0s 
[+] Running 2/2
 ✔ Network dockercompose_default  Creat...                                 0.0s 
 ✔ Container dockercompose-db-1   Starte...  achaodeMacBook-Pro:DockerCompose achao$ docker-compose -f mysql-compose.yml up -d
[+] Running 12/12
 ✔ db 11 layers [⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿]      0B/0B      Pulled                      37.6s 
   ✔ 29e800056b7e Pull complete                                            9.7s 
   ✔ 69da292eb326 Pull complete                                            9.8s 
   ✔ 8850ef02dd58 Pull complete                                            9.8s 
   ✔ 86a76caa9e20 Pull complete                                            9.9s 
   ✔ 881324b10832 Pull complete                                            9.9s 
   ✔ 1f5d1a8fa489 Pull complete                                            9.9s 
   ✔ 5efbe9eacf59 Pull complete                                           19.8s 
   ✔ 80db22f26c0f Pull complete                                           19.8s 
   ✔ e5595b935c31 Pull complete                                           32.8s 
   ✔ c391d4efe159 Pull complete                                           32.8s 
   ✔ e5527cf2eb5f Pull complete                                           32.8s 
[+] Running 0/1
 ⠿ Container dockercompose-db-1  Startin...                                0.4s 
Error response from daemon: Mounts denied: 
The path /Library/DockerCompose/my.cnf is not shared from the host and is not known to Docker.
You can configure shared paths from Docker -> Preferences... -> Resources -> File Sharing.
See https://docs.docker.com/desktop/mac for more info.                              0.6s

发现这里提示is not shared from the host and is not known to Docker.

我们配置一下,删除容器和镜像,重新运行

代码语言:javascript
复制
achaodeMacBook-Pro:DockerCompose achao$ docker ps -a
CONTAINER ID   IMAGE     COMMAND                   CREATED         STATUS                    PORTS                    NAMES
8ab032076233   mysql     "docker-entrypoint.s…"   4 minutes ago   Created                                            dockercompose-db-1
671e95fa6e2e   redis     "docker-entrypoint.s…"   31 hours ago    Exited (0) 26 hours ago   0.0.0.0:6379->6379/tcp   some-redis
achaodeMacBook-Pro:DockerCompose achao$ docker rm 8ab032076233
8ab032076233
achaodeMacBook-Pro:DockerCompose achao$ docker rmi mysql
Untagged: mysql:latest
Untagged: mysql@sha256:232936eb036d444045da2b87a90d48241c60b68b376caf509051cb6cffea6fdc
Deleted: sha256:772571a08c67835aed7436d84973e885cc439b6cdd4dd1cc661a907d8acd3591
Deleted: sha256:433770b08a2dd41a86a333367033160b17606e5ebb2b92631ec78b4271fc6960
Deleted: sha256:b29b12491e1e17258cf08faba990bf68796bc64cbecfaaefb7589c51728dfe0b
Deleted: sha256:686d2473026cd05e2b4c65f8d4d65323c20c41a1cf1f7335a0aea3470d2377fc
Deleted: sha256:95835cb02d6b78021bcec36d9c34e336c9c66520d6c429d71c03091c87fb17aa
Deleted: sha256:fb6fd46d33af700630b4d596a8daebc559e9af5b03050929d121b2ae96e076fc
Deleted: sha256:d6f1d939e095f4854e964197f993d5827c89ad6d397cf08813e09b57be77c1cc
Deleted: sha256:241384476c4f937e16d507a015ca4c2e73e50a33fd09671b00fcbc348c3d1de3
Deleted: sha256:0722bbaa4d8469983c449492605faa50beacecaae2b7543b97796b40d2fe8574
Deleted: sha256:a78744b20069e25e25a35cf6b52d1307577c35123960c8b7a91725ddd824f1bc
Deleted: sha256:ad2eba511a7c8004e9b643b46974b6a9d28ba1039b8c27f6900638f260b5bd18
Deleted: sha256:901c6235ed257542c09d413355d472fcc809db93f6dbe91ddc6790a53d698d2c
achaodeMacBook-Pro:DockerCompose achao$ docker-compose -f mysql-compose.yml up -d
[+] Running 12/12
 ✔ db 11 layers [⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿]      0B/0B      Pulled                      34.5s 
   ✔ 29e800056b7e Pull complete                                            9.4s 
   ✔ 69da292eb326 Pull complete                                            9.4s 
   ✔ 8850ef02dd58 Pull complete                                            9.4s 
   ✔ 86a76caa9e20 Pull complete                                           12.4s 
   ✔ 881324b10832 Pull complete                                           12.4s 
   ✔ 1f5d1a8fa489 Pull complete                                           12.4s 
   ✔ 5efbe9eacf59 Pull complete                                           19.8s 
   ✔ 80db22f26c0f Pull complete                                           19.8s 
   ✔ e5595b935c31 Pull complete                                           29.7s 
   ✔ c391d4efe159 Pull complete                                           29.7s 
   ✔ e5527cf2eb5f Pull complete                                           29.8s 
[+] Running 1/1
 ✔ Container dockercompose-db-1  Started                                   0.4s

然后查询测试

代码语言:javascript
复制
show global variables like '%lower_case%';
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-07-16,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
容器镜像服务
容器镜像服务(Tencent Container Registry,TCR)为您提供安全独享、高性能的容器镜像托管分发服务。您可同时在全球多个地域创建独享实例,以实现容器镜像的就近拉取,降低拉取时间,节约带宽成本。TCR 提供细颗粒度的权限管理及访问控制,保障您的数据安全。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档