docker创建mysql8、并设置表名和字段不区分大小写配置

1.拉取 MySQL 镜像

docker pull mysql:latest

2.安装运行mysql

docker run -itd --name mysql8.0 \
-p 3306:3306  -e MYSQL_ROOT_PASSWORD=root \
-v /home/workspace/mysql:/var/lib/mysql --restart=always \
-e TZ="Asia/Shanghai" mysql --lower_case_table_names=1

注意修改 MYSQL_ROOT_PASSWORD=root ,将root换成自己想要的密码。

--lower_case_table_names=1 这个参数是设置不区分大小写的

3.更新my.cnf(mysql 高版本 sql_mode=only_full_group_by 问题解决方法).

进入到mysql8.0容器

    docker exec -it mysql8.0 bash

安装VIM

apt-get update
apt-get install vim

在/etc/mysql/目录修改my.cnf配置文件

vim /etc/mysql/my.cnf

增加sql_mode

sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'

保存my.cnf并重启mysql容器就生效了。

修改后可以将容器commit打包为一个新的镜像,这以后就用这个打包后的镜像,都自动配置了 。

这种如果觉得麻烦的话,可以将mysql的my.cnf配置文件挂载到宿主机目录,直接在宿主机上编辑文件。

my.cnf配置文件如下:

# Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

#
# The MySQL  Server configuration file.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html

[mysqld]
pid-file        = /var/run/mysqld/mysqld.pid
socket          = /var/run/mysqld/mysqld.sock
datadir         = /var/lib/mysql
secure-file-priv= NULL
sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'


# Custom config should go here
!includedir /etc/mysql/conf.d/

如果不想弄,我自己打包的镜像可以下载直接导入用: 

        镜像下载地址:

https://download.csdn.net/download/houjiezhuang/62121430https://download.csdn.net/download/houjiezhuang/62121430        镜像如何导入、运行:

使用Portainer导入docker镜像并运行_houjiezhuang的博客-CSDN博客使用Portainer导入docker镜像并运行https://blog.csdn.net/houjiezhuang/article/details/121898686

你可能感兴趣的:(docker,mysql,docker,mysql,容器)