docker配置mysql,忽略大小写

作者: gavin 分类: Docker 发布时间: 2023-11-07 09:28

一、部署5.6数据库的目录映射

docker run -itd --name mysql0 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 --privileged=true -v /home/app/mysql/log:/var/log/ -v /home/app/mysql/data:/var/lib/mysql -v /home/app/mysql/conf:/etc/mysql mysql:5.6

二、部署5.7的话配置文件目录需要修改下

docker run -itd --name mysql -p 3832:3306 -e MYSQL_ROOT_PASSWORD=Chat89328932 --privileged=true -v /home/app/mysql/log:/var/log/ -v /home/app/mysql/data:/var/lib/mysql -v /home/app/mysql/conf:/etc/mysql/conf.d mysql:5.7

三、配置文件提前放在conf目录:my.cnf

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
character-set-server=utf8mb4
collation-server=utf8mb4_general_ci
init_connect='SET NAMES utf8mb4'
# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password
default-authentication-plugin=mysql_native_password
lower_case_table_names=1
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
skip-host-cache
skip-name-resolve
datadir=/var/lib/mysql
socket=/var/run/mysqld/mysqld.sock
secure-file-priv=/var/lib/mysql-files
user=mysql
pid-file=/var/run/mysqld/mysqld.pid
[client]
socket=/var/run/mysqld/mysqld.sock

四、登录数据库查询是否已经忽略了大小写

#进入容器
docker exec -it mysql bash

#进入mysql
mysql -uroot -p123456

#查询是否忽略大小写
SHOW VARIABLES LIKE 'lower_case_table_names';

+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| lower_case_table_names | 1     |
+------------------------+-------+

0:表示大小写敏感,表名和数据库名区分大小写。
1:表示表名不区分大小写,但数据库名区分大小写。
2:表示表名和数据库名都不区分大小写。

五、如果需要运行canal,还需要配置这三行参数

[mysqld]
server-id = 1
binlog_format = ROW
log_bin = mysql_bin

六、配置保存后重启mysql

show variables like 'log_bin';

+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| log_bin       | ON    |
+---------------+-------+

#出现on,就代表配置成功了