mysql 8.0.18的docker安装

1.拉取镜像

sudo docker pull mysql:8.0.18

编辑配置文件

/home/cy/soft/mysql/conf/mysql.conf

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.1/en/server-configuration-defaults.html

[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

# 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.1/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password
# innodb缓冲池大小
innodb_buffer_pool_size=5600M
 
# innodb缓冲池块大小
innodb_buffer_pool_chunk_size=700M
 
# innodb缓冲池实例数
innodb_buffer_pool_instances=8

# 连接操作缓冲区,默认256K

join_buffer_size = 8M

# 排序操作缓冲区,默认256K
sort_buffer_size = 8M

# 顺序读取缓冲区,默认128K

read_buffer_size = 4M

# 随机读取缓冲区,默认128K
read_rnd_buffer_size = 8M

skip-host-cache
skip-name-resolve

datadir=/var/lib/mysql
socket=/var/run/mysqld/mysqld.sock
secure-file-priv=NULL
pid-file=/var/run/mysqld/mysqld.pid

!includedir /etc/mysql/conf.d/
View Code

 

2.运行docker

sudo docker run -p 3306:3306 --name mysql --restart=always --privileged=true \
-v /home/cy/soft/mysql/conf/mysql/log:/var/log/mysql \
-v /home/cy/soft/mysql/data:/var/lib/mysql \
-v /home/cy/soft/mysql/conf/mysql.conf:/etc/mysql/my.cnf \
-v /etc/localtime:/etc/localtime:ro \
-e MYSQL_ROOT_PASSWORD=123456 -d mysql:8.0.18

3.查看日志

sudo docker logs -f 78ffe50725abf4f8ef862de8e5f5890961a70a820ed39952b5a28a00b26f3af9

4.mysql登录

mysql -h localhost -P 3306 -u root

5.mysql进入容器

sudo docker exec -it 78ffe50725abf4f8ef862de8e5f5890961a70a820ed39952b5a28a00b26f3af9 /bin/bash

6.java连接mysql

出现“Public Key Retrieval is not allowed

禁用 SSL/TLS 协议,在 JDBC 连接串中添加 allowPublicKeyRetrieval 参数并设置为 true 来允许公钥检索。这样一来,即使禁用了 SSL/TLS 协议,客户端仍然可以通过此参数获取服务器的公钥,从而避免“Public Key Retrieval is not allowed”错误

          url: jdbc:mysql://localhost:3306/test?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true
          username: root
          password: 123456
          driver-class-name: com.mysql.cj.jdbc.Driver 

 

posted @ 2024-05-27 22:17  24601  阅读(24)  评论(0编辑  收藏  举报