docker安装mysql8.0
1.创建对应目录
mkdir -p /data/mysql8/data/{data,log,my.conf.d,mysql-files}
chmod -R 777 /data/mysql8/
cd /data/mysql8/data/my.conf.d/
vi my.cnf
[client]
# 默认字符集
#default-character-set=utf8
[mysql]
# 默认字符集
#default-character-set=utf8
[mysqld]
#
server-id=01
port=3306
## 开启二进制日志功能
log-bin=mysql-slave-bin
## relay_log配置中继日志
relay_log=edu-mysql-relay-bin
# 忽略大小写
lower_case_table_names=1
pid-file= /var/run/mysqld/mysqld.pid
socket= /var/run/mysqld/mysqld.sock
# 数据库数据存放目录
datadir= /var/lib/mysql
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
skip-symbolic-links=0
# 最大链接数
max_connections=200
# 最大失败次数
max_connect_errors=10
# 默认时区
default-time_zone='+8:00'
character-set-client-handshake=FALSE
character_set_server=utf8mb4
# default-character-set=utf8
collation-server=utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci'
# 默认使用‘mysql_native_password’插件认证
default_authentication_plugin=mysql_native_password
# Custom config should go here
!includedir /etc/mysql/conf.d/
2.启动服务
docker run -itd \
-p 3306:3306 \
-e MYSQL_ROOT_HOST=% \
-e MYSQL_ROOT_PASSWORD=testhh@mysql8 \
-v /data/mysql8/data/data:/var/lib/mysql:rw \
-v /data/mysql8/data/log:/var/log/mysql:rw \
-v /data/mysql8/data/my.conf.d/my.cnf:/etc/mysql/my.cnf:rw \
-v /data/mysql8/data/mysql-files:/var/lib/mysql-files:rw \
--name mysql8 \
--privileged=true \
--restart=always \
-d mysql:8.0
3.修改密码连接模式
docker exec -it mysql8 /bin/bash
mysql -uroot -p'123456'
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';