How to install mysql-8.0 as systemd service with podman

创建卷

podman volume create --label type=mysql-8.0 --label env=dev mysql-8.0-data
podman volume create --label type=mysql-8.0 --label env=dev mysql-8.0-conf

创建用户服务目录

mkdir -p ~/.config/systemd/user

创建用户容器

podman create  \
--restart always \
--publish 23306:3306 \
--name mysql-8.0 \
--volume mysql-8.0-data:/var/lib/mysql \
--volume mysql-8.0-conf:/etc/mysql \
--volume /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime \
--env MYSQL_ROOT_PASSWORD=Gah6kuP7ohfio4 \
mysql:8.0.36

如果是启动容器的话,可以用下面的脚本

podman run  --detach \
--restart always \
--publish 23306:3306 \
--name mysql-8.0 \
--volume mysql-8.0-data:/var/lib/mysql \
--volume mysql-8.0-conf:/etc/mysql \
--volume /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime \
--env MYSQL_ROOT_PASSWORD=Gah6kuP7ohfio4 \
mysql:8.0.36

如果要将系统变量innodb_strict_mode调整为OFF,需要用下述脚本启动

podman run  --detach \
--restart always \
--publish 23306:3306 \
--name mysql-8.0 \
--volume mysql-8.0-data:/var/lib/mysql \
--volume mysql-8.0-conf:/etc/mysql \
--volume /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime \
--env MYSQL_ROOT_PASSWORD=Gah6kuP7ohfio4 \
mysql:8.0.36 --innodb-strict-mode=false

启动以后,可以在mysql的console中用下述脚本验证

lwk@qwfys:~$ mysql -h 127.0.0.1 -u root -P 23306 -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 134
Server version: 8.0.36 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show variables like '%innodb_strict_mode%';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| innodb_strict_mode | OFF   |
+--------------------+-------+
1 row in set (0.01 sec)

mysql> 

如果要将系统变量lower_case_table_names调整为1,也就是说,让mysql对于大小写不敏感,需要用下述脚本启动

podman run  --detach \
--restart always \
--publish 23306:3306 \
--name mysql-8.0 \
--volume mysql-8.0-data:/var/lib/mysql \
--volume mysql-8.0-conf:/etc/mysql \
--volume /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime \
--env MYSQL_ROOT_PASSWORD=Gah6kuP7ohfio4 \
mysql:8.0.36 --lower-case-table-names=1

这里需要说明一下,由于mysql 8.0的限制,采用上述脚本启动的时候,如果挂载了卷,需要在一个干净的卷上操作,否则操作不成功。

验证脚本如下:

lwk@qwfys:~$ mysql -h 127.0.0.1 -u root -P 23306 -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 134
Server version: 8.0.36 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show variables like '%lower_case_table_names%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| lower_case_table_names | 1     |
+------------------------+-------+
1 row in set (0.01 sec)

mysql> 

如果将上述两个启动参数一起添加上,脚本如下

podman run  --detach \
--restart always \
--publish 23306:3306 \
--name mysql-8.0 \
--volume mysql-8.0-data:/var/lib/mysql \
--volume mysql-8.0-conf:/etc/mysql \
--volume /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime \
--env MYSQL_ROOT_PASSWORD=Gah6kuP7ohfio4 \
mysql:8.0.36 --innodb-strict-mode=false --lower-case-table-names=1

效果可以通过下而把脚本验证

lwk@qwfys:~$ mysql -h 127.0.0.1 -u root -P 23306 -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 134
Server version: 8.0.36 MySQL Community Server - GPL

Copyright (c) 2000, 2024, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show variables like '%innodb_strict_mode%';
+--------------------+-------+
| Variable_name      | Value |
+--------------------+-------+
| innodb_strict_mode | OFF   |
+--------------------+-------+
1 row in set (0.01 sec)

mysql> show variables like '%lower_case_table_names%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| lower_case_table_names | 1     |
+------------------------+-------+
1 row in set (0.01 sec)

mysql> 

mysql docker启动参数有很多,通常情况下,我们不需要记忆,只需要掌握如果查找这些启动参数即可,依据官方相关说明,我们可以借助如下脚本列出所有启动参数:

podman run -it --rm mysql:8.0.36 --verbose --help

接下来,我们基于podman完成用户服务的创建

podman generate systemd --new mysql-8.0 > ~/.config/systemd/user/mysql-8.0.service

重新加载

systemctl --user daemon-reload

启用开机启动

systemctl --user enable mysql-8.0.service

查看状态

systemctl --user status mysql-8.0.service

启动

systemctl --user start mysql-8.0.service

停服

systemctl --user stop mysql-8.0.service

重启

systemctl --user restart mysql-8.0.service
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

qwfys200

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值