您的位置:首页 > 新闻 > 热点要闻 > How to install mysql 5.7 with podman in Ubuntu 24.04

How to install mysql 5.7 with podman in Ubuntu 24.04

2025/4/6 0:57:17 来源:https://blog.csdn.net/qwfys200/article/details/141723892  浏览:    关键词:How to install mysql 5.7 with podman in Ubuntu 24.04

How to install mysql 5.7 with podman in Ubuntu 24.04

概述

今天我们介绍一下如何在Ubuntu server 22.04以Podman方式安装。

配置卷

名称位置用途
mysql-5.7 conf/data/docker/mysql-5.7/conf/conf.dmysql-5.7配置目录
mysql-5.7 conf/data/docker/mysql-5.7/conf/mysql.conf.dmysql-5.7配置目录
mysql-5.7 data/data/docker/mysql5.7/datamysql-5.7数据目录
sudo mkdir -p /data
sudo chown ylzx:ylzx -R /data
mkdir -p /data/docker/mysql-5.7/conf/conf.d
mkdir -p /data/docker/mysql-5.7/conf/mysql.conf.d
mkdir -p /data/docker/gitlab/data

运行

考虑到mysql5.7官方镜像的特殊性,不能直接挂载本地目录做为卷,需要完成以下步骤以后才可以挂载上本地目录卷。

  • 步骤 1

运行一个不挂载卷的容器

podman run  --detach \
--restart always \
--publish 13306:3306 \
--name mysql-5.7 \
--volume /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime \
--env MYSQL_ROOT_PASSWORD=Gah6kuP7ohfio4 \
mysql:5.7.44
  • 步骤 2

podman cp命令复制出容器中的目录到本地,命令如下:

podman cp mysql-5.7:/etc/mysql/conf.d /data/docker/mysql-5.7/conf/conf.d
podman cp mysql-5.7:/etc/mysql/mysql.conf.d /data/docker/mysql-5.7/conf/mysql.conf.d
  • 步骤3

挂载卷运行,命令如下

podman run  --detach \
--restart always \
--publish 13306:3306 \
--name mysql-5.7 \
--volume /data/docker/mysql-5.7/conf/conf.d:/etc/mysql/conf.d \
--volume /data/docker/mysql-5.7/conf/mysql.conf.d:/etc/mysql/mysql.conf.d \
--volume /data/docker/mysql-5.7/data:/var/lib/mysql \
--volume /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime \
--env MYSQL_ROOT_PASSWORD=Gah6kuP7ohfio4 \
mysql:5.7.44

查看

lwk@qwfys:~$ podman ps -a
CONTAINER ID  IMAGE                              COMMAND          CREATED         STATUS                PORTS                                         NAMES
191b58ff003f  docker.io/gitlab/gitlab-ce:latest  /assets/wrapper  2 hours ago     Up 2 hours (healthy)  0.0.0.0:10022->22/tcp, 0.0.0.0:19000->80/tcp  gitlab
295b77ee2d0f  docker.io/library/mysql:5.7.44     mysqld           31 minutes ago  Up 31 minutes         0.0.0.0:13306->3306/tcp                       mysql-5.7
ylzx@scyl043:/data/docker/mysql-5.7/conf$ 

访问页面

经过上述安装以后,mysql就安装好了,我们可以直接使用了。

在没有mysql客户端的时候,我们也可以用docker容器做为客户端来验证一下,上述安装有没有成功。示例如下:

lwk@qwfys:~$ podman run -it --rm mysql:5.7.44 mysql \--host=192.168.0.4 \--port=13306 \--user=root \--password \--database=mysql
Enter password: 
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -AWelcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.44 MySQL Community Server (GPL)Copyright (c) 2000, 2023, 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 databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)mysql> exit
Bye
lwk@qwfys:~$

spring boot项目中使用的话,可以用下述方式访问mysql 5.7数据库

spring:datasource:hikari:jdbc-url: jdbc:mysql://192.168.0.4:13306/mysql?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=Asia/Shanghaiusername: rootpassword: Gah6kuP7ohfio4

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com