docker容器中调整Mysql忽略大小写

1、进入容器

docker exec -it mysql /bin/bash
或者
docker exec -it mysql bash

2、登录Mysql,查看"lower_case_table_names"变量值

show global variables like '%lower_case%';

[root@qianyi-obs ~]# mysql -hx.x.x.x -P30036 -uroot -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 51528
Server version: 5.7.36 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show global variables like '%lower_case%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| lower_case_file_system | OFF   |
| lower_case_table_names | 0     |
+------------------------+-------+
2 rows in set (0.00 sec)

 3、进入容器,编辑/etc/mysql/mysql.conf.d/mysqld.cnf

cat > mysqld.cnf << EOF
[mysqld]
pid-file	= /var/run/mysqld/mysqld.pid
socket		= /var/run/mysqld/mysqld.sock
datadir		= /var/lib/mysql
lower_case_table_names=1
#log-error	= /var/log/mysql/error.log
# By default we only accept connections from localhost
#bind-address	= 127.0.0.1
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
EOF

4、退出容器,重启Mysql容器

docker restart mysql

5、验证修改是否成功

 6、如果用docker-compose启动,需要将本地mysqld.cnf挂载到容器中

version: "3"
services:
    mysql:
        image: mysql:5.7
        container_name: mysql
        env_file:
                - .env
        ports:
                - "30036:3306"
        restart: always
        volumes:
                - ./mysql/config-file.cnf:/etc/mysql/conf.d/config-file.cnf
                - ./mysql/data:/var/lib/mysql
                - ./mysql/init.sql:/docker-entrypoint-initdb.d/init.sql
                - /etc/hosts:/etc/hosts
        healthcheck:
                test: mysqladmin ping -h127.0.0.1 -uroot --password=123xxxxxx
                interval: 1s
                timeout: 3s
                retries: 10
        networks:
                - sky-net
networks:
    sky-net:
        driver: bridge