Docker 安装 MySQL8

1. 环境准备

创建挂载数据目录和配置文件

mkdir -p /mnt/mysql/data /etc/mysql/conf
touch /etc/mysql/conf/my.cnf

2. 拉取镜像

docker pull mysql

3. 启动容器

docker run --restart=always --name=mysql -p 3306:3306 \
-v /etc/mysql/conf/my.cnf:/etc/my.cnf \
-v /mnt/mysql/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-d mysql

4. 配置远程访问

docker exec -it mysql /bin/bash
mysql -uroot -p123456
alter user 'root'@'%' identified by '123456' password expire never;
alter user 'root'@'%' identified with mysql_native_password by '123456';
flush privileges;

posted @ 2021-02-11 18:06  有来技术  阅读(1107)  评论(0编辑  收藏  举报