美文网首页
Docker Compose 部署mysql

Docker Compose 部署mysql

作者: 刘杰克 | 来源:发表于2020-03-05 14:01 被阅读0次

    编写docker-compose.yml

    version: '3.1'
    services:
      db:
        image: mysql
        restart: always
        environment:
          MYSQL_ROOT_PASSWORD: 123456
        command:
          --default-authentication-plugin=mysql_native_password
          --character-set-server=utf8mb4
          --collation-server=utf8mb4_general_ci
          --explicit_defaults_for_timestamp=true
          --lower_case_table_names=1
        ports:
          - 3306:3306
        volumes:
          - ./data:/var/lib/mysql
    

    部署mysql, 执行以下命令

    $docker-compose up -d
    

    navicat连接mysql

    进入已启动的mysql 容器,527ad517ee71为容器ID

    $docker exec -it 527ad517ee71 bash
    

    进入mysql

    [root@izbp10fk8pd9zjv9y2g9ajz etc]# mysql -u root -p
    Enter password:
    

    更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%",执行以下命令

    update user set host = '%' where user ='root';
    

    更新配置,执行以下命令

    flush privileges;
    

    相关文章

      网友评论

          本文标题:Docker Compose 部署mysql

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