美文网首页
Docker Compose部署MySQL

Docker Compose部署MySQL

作者: LainCheung | 来源:发表于2019-05-07 17:43 被阅读0次

    docker-compose.yml配置

    version: '3'
    
    services:
      mysql:
        image: mysql:latest
        container_name: mysql
        restart: always
        environment:
          MYSQL_ROOT_PASSWORD: "123456"
        ports:
          - 3306:3306
        volumes:
          - ./datas:/var/lib/mysql:rw
          - ./conf/my.cnf:/etc/my.cnf:rw
          - ./init:/docker-entrypoint-initdb.d/:ro
        command: 
          --default-authentication-plugin=mysql_native_password #这行代码解决无法访问的问题
    

    my.cnf配置

    [mysqld]
    user=mysql
    default-storage-engine=INNODB
    character-set-server=utf8
    [client]
    default-character-set=utf8
    [mysql]
    default-character-set=utf8
    

    配置init.sql(服务创建时自动执行)

    use mysql;
    ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'password';
    FLUSH PRIVILEGES;
    

    相关文章

      网友评论

          本文标题:Docker Compose部署MySQL

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