美文网首页
docker-compose mysql8安装

docker-compose mysql8安装

作者: Ucan先生 | 来源:发表于2020-02-28 22:50 被阅读0次

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即可

相关文章

网友评论

      本文标题:docker-compose mysql8安装

      本文链接:https://www.haomeiwen.com/subject/ljsdhhtx.html