docker-compose mysql8安装
2020-02-28 本文已影响0人
Ucan先生
docker-compose.yml
version: '3'
services:
mysql-db-dev:
container_name: mysql-docker-dev # 指定容器的名称
image: mysql:8.0 # 指定镜像和版本
ports:
- "33062:3306"
environment:
MYSQL_ROOT_PASSWORD: 123456
#env_file: 设置环境变量文件
# - .env
volumes:
- ./data:/var/lib/mysql" # 挂载数据目录
- ./conf.d:/etc/mysql/conf.d" # 挂载配置文件目录
- ./my.cnf:/etc/my.cnf
my.cnf 设置字符集为utf8mb4 解决emoji表情等特殊字符存储问题
[client]
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init_connect='SET NAMES utf8mb4'
docker-compose up -d
安装后尝试 mysql 127.0.0.1 -P33062 -uroot -p'123456' 报错
RROR 2059 (HY000): Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory
解决办法
docker ps 找到对应容器ID
docker exec -it container_id /bin/sh
mysql -h127.0.0.1 -uroot -p'123456'
alter user 'root'@'%' identified with mysql_native_password by '123456';
重新登陆mysql即可