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

本文详细介绍了如何使用Docker拉取并安装MySQL8.0镜像,包括设置自定义密码、不区分大小写参数以及解决sql_mode问题。通过修改my.cnf文件,添加指定的sql_mode,然后保存并重启容器以使配置生效。此外,还提供了将容器commit为新镜像的方法,以及直接下载已配置好的镜像链接。
摘要由CSDN通过智能技术生成

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

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值