侧边栏壁纸
  • 累计撰写 123 篇文章
  • 累计创建 27 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

Docker运行的MySQL5.7修改忽略大小写

梁来福
2024-09-11 / 0 评论 / 0 点赞 / 4 阅读 / 3512 字
温馨提示:
本文最后更新于 2024-09-11,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

背景

现机器上使用Docker部署了MySQL5.7,不清楚具体启动过程。现需要修改MySQL忽略大小写配置,本想着直接拷贝一份my.cnf配置文件到MySQL容器内,结果报错:

[root@new-test conf]# docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED       STATUS         PORTS                                                                                  NAMES
26535ee6c007   percona:5.7.26           "/docker-entrypoint.…"   3 years ago   Up 3 years   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp                                              percona3306
[root@new-test ~]# docker cp my.cnf percona3306:/etc/my.cnf
Error response from daemon: Error processing tar file(exit status 1): unlinkat /etc/percona-server.cnf: device or resource busy

错误原因

这个错误的原因是MySQL启动方式使用了挂载命令,配置文件挂载到了宿主机某个目录下

解决

直接修改宿主机配置文件重启MySQL容器即可

# 查看MySQL挂载的目录
[root@new-test ~]# docker inspect percona3306 | grep Mounts -A 20
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/data/mysql/3306/conf/my.cnf",
                "Destination": "/etc/my.cnf",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/data/mysql/3306/data",
                "Destination": "/var/lib/mysql",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "volume",
                "Name": "3fe18a8bb9898064064b4496f63d68bd5a457cabbf09225067b7a99b95b616a5",
                "Source": "/data/docker/volumes/3fe18a8bb9898064064b4496f63d68bd5a457cabbf09225067b7a99b95b616a5/_data",

# 修改配置文件my.cnf
[root@new-test conf]# cat /data/mysql/3306/conf/my.cnf
[mysqld]
user=mysql
explicit_defaults_for_timestamp=true
character-set-server=utf8mb4
default_authentication_plugin=mysql_native_password
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
max_connections=2000
lower_case_table_names=1 # 忽略大小写

[client]
default-character-set=utf8mb4

[mysql]
default-character-set=utf8mb4

# 重启MySQL容器
[root@new-test conf]# docker restart percona3306
percona3306

验证

# 首先查看MySQL容器地址
[root@new-test conf]# docker inspect percona3306 | grep -i "IPAddress"
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.5",
                    "IPAddress": "172.17.0.5",

# 验证
[root@new-test conf]# mysql -h172.17.0.5 -uroot -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.26-29 Percona Server (GPL), Release 29, Revision 11ad961

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 | 1     |
+------------------------+-------+
2 rows in set (0.00 sec)

MySQL [(none)]> exit
Bye

0
博主关闭了所有页面的评论