docker安装mysql8步骤

1.创建需要挂载的目录,如图:

mysql-files文件记得也挂载,不然启动报错

2.编写mysql8配置文件:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html
# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the
# *** default location during install, and will be replaced if you
# *** upgrade to a newer version of MySQL.

[mysql]
#设置以下配置相当于同时设置了character_set_client(客户端)、character_set_connection(连接)、character_set_result(返回结果)的字符集均为utf8
default_character_set=utf8mb4

#设置客户端连接的校对规则(排序规则)
#collation_connection=utf8mb4_bin

[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

# These are commonly set, remove the # and set as required.
#basedir = "./"
#datadir = "./data"
port = 3306
# server_id = .....

#设置默认时区为东八区
default_time_zone='+8:00'

#设置服务器级别的字符编码使用utf8mb4,如不单独设置数据库级别、表级别、字段级别的字符集,则默认都使用服务器级别的字符编码
#建议使用utf8mb4代替之前的utf8,utf8mb4是4个字节的unicode编码,而utf8最多使用3个字节的unicode编码,并不是真正的UTF-8编码,
#会导致部分特殊的字符无法插入
character_set_server=utf8mb4

#设置字符集的校对规则(排序规则)为大小写敏感的,不然会导致某些敏感数据不区分大小写,导致业务上出问题
collation_server=utf8mb4_bin

#修改 发送给服务器的最大数据包大小
max_allowed_packet=20M
#设置表明不区分大小写(windows下默认都是不区分的,如果配置了会启动失败,linux下的话需要设置,不然容易出现表不存在的错误,特别是使用quatz等自动生成表的框架,有可能生成的表示大写的,代码或者sql使用小写的去查询就会报错)
#lower_case_table_names=0 

# 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 

#解决mysql启动报timestamp的警告问题,关闭timestamp的默认,如需要DEFAULT CURRENT_TIMESTAMP和ON UPDATE,需显示指定默认值为timestamp类型的字段
explicit_defaults_for_timestamp=true
# 默认使用“mysql_native_password”插件认证
default_authentication_plugin=mysql_native_password

3.启动mysql8容器,命令:

docker run --name mysql8 -v /opt/docker/mysql/mysql8/my.cnf:/etc/mysql/my.cnf -v /opt/docker/mysql/mysql8/data:/var/lib/mysql -v /opt/docker/mysql/mysql8/logs:/var/log/mysql -v /opt/docker/mysql/mysql8/mysql-files:/var/lib/mysql-files/ -e MYSQL_ROOT_PASSWORD=123456 -d -p 3308:3306 mysql:8.0.19

4.进入mysql 容器,修改允许远程访问:

docker exec -it mysql8 bash
mysql -uroot -p123456
GRANT ALL ON *.* TO 'root'@'%' with grant option;
flush privileges;

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值