mysql8 docker 安装
1. 镜像下载
docker pull mysql:8.0.21
2. 创建目录
创建data,conf等目录,用于保存mysql的数据
1. my.cnf
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
port=3306
character-set-server=UTF8MB4
lower_case_table_names = 1
sql-mode = STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
``
### 3. 启动镜像
docker run -it -d --name mysql --net=host \
-v /var/application/mysql8/data:/var/lib/mysql \
-v /var/application/mysql8/mysql-files:/var/lib/mysql-files \
-v /var/application/mysql8/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
-e TZ=Asia/Shanghai mysql:8.0.21 \
--lower_case_table_names=1
data: mysql数据
conf: 配置文件
mysql-file: 配置文件挂载到宿主机时,需要将该目录挂载,否则启动报错
## 4. 进入容器, 修改连接配置
ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY 'test@123';
flush privileges;
如果文章对您有所帮助,可以点一下推荐