- 创建配置目录
bash
mkdir -p ~/data/podman/mysql-8.0/etc
- 创建数据存储目录
bash
mkdir -p ~/data/podman/mysql-8.0/var
- 临时启动一个实例
bash
docker run --detach \
--restart always \
--publish 23306:3306 \
--name mysql-8.0 \
--volume /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime \
--env MYSQL_ROOT_PASSWORD=Gah6kuP7ohfio4 \
mysql:8.0.34
- 复制原始配置到宿主机
bash
cp cp mysql-8.0:/etc/mysql/conf.d ~/data/podman/mysql-8.0/etc/conf.d
podman cp mysql-8.0:/var/lib/mysql ~data/podman/mysql-8.0/var
- 移除该实例
bash
podman stop mysql-8.0
bash
podman rm mysql-8.0
- 重新正式开启一个实例
bash
podman run --detach \
--restart always \
--publish 23306:3306 \
--name mysql-8.0 \
--volume ~/data/podman/mysql-8.0/var:/var/lib/mysql \
--volume ~/data/podman/mysql-8.0/etc/conf.d:/etc/mysql/conf.d \
--volume /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime \
--env MYSQL_ROOT_PASSWORD=Gah6kuP7ohfio4 \
mysql:8.0.34
- 查看实例
bash
lwk@qwfys:~$ podman ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1647d61060aa mysql:8.0.23 "docker-entrypoint.s..." 31 minutes ago Up 31 minutes 33060/tcp, 0.0.0.0:23306->3306/tcp, :::23306->3306/tcp mysql-8.0
lwk@qwfys:~$
- 访问实例
yaml
spring:
datasource:
hikari:
jdbc-url: jdbc:mysql://127.0.01:23306/mysql?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghai
username: root
password: Gah6kuP7ohfio4
- 关闭实例
bash
podman stop mysql-8.0
- 删除实例
bash
podman rm mysql-8.0