start mysql8 in docker,use ~/mysql/data to persist data

docker-compose.yml

version: '3.1'
services:
  mysql:
    image: mysql:8
    container_name: mysql
    command: --default-authentication-plugin=mysql_native_password
    volumes:
      - mysql-data:/var/lib/mysql
    ports:
      - 3306:3306
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: {your password}
      TZ: Asia/Shanghai
    network_mode: bridge

volumes:
  mysql-data:
    external: true