hj-cloud-02-docker-mysql
podman安装mysql
https://hub.docker.com/_/mysql/tags 查找mysql镜像tag , podman search mysql --filter=stars=100 搜索镜像
[root@VM-12-9-opencloudos hj_files]# podman search mysql --filter=stars=100 NAME DESCRIPTION docker.io/library/mysql MySQL is a widely used, open-source relation... docker.io/library/mariadb MariaDB Server is a high performing open sou... docker.io/library/percona Percona Server is a fork of the MySQL relati... docker.io/library/phpmyadmin phpMyAdmin - A web interface for MySQL and M...
// 还是直接拉取5.7.41版本吧
podman pull mysql:5.7.41
[root@VM-12-9-opencloudos hj_files]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/library/mysql 5.7.41 8aea3fb7309a 2 days ago 472 MB
简单需求: 配置文件,数据挂载到外部文件.端口号改成3307,密码访问
podman run -d -p 3306:3306 --name hj_mysql57 -e MYSQL_ROOT_PASSWORD=root 8aea3fb7309a
podman exec -it 5ba01550ab60 /bin/bash
[root@VM-12-9-opencloudos hj_files]# podman run -d -p 3306:3306 --name hj_mysql57 -e MYSQL_ROOT_PASSWORD=root 8aea3fb7309a
5ba01550ab6025478f62df6d9a74801223ede9b5400b5a1d0c48e776382cb2be
[root@VM-12-9-opencloudos hj_files]# podman ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5ba01550ab60 docker.io/library/mysql:5.7.41 mysqld 5 seconds ago Up 5 seconds ago 0.0.0.0:3306->3306/tcp hj_mysql57
[root@VM-12-9-opencloudos hj_files]# podman exec -it 5ba01550ab60 /bin/bash
bash-4.2# mysql --help | grep my.cnf
order of preference, my.cnf, $MYSQL_TCP_PORT,
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
bash-4.2#
// 容器内的文件拷贝出去 外部先创建好文件夹.退出容器进行拷贝操作
podman cp 5ba01550ab60:/etc/mysql/. /hj_files/hj_mysql57/conf --这个版本mysql文件夹下的两个文件夹都是null
podman cp 5ba01550ab60:/etc/my.cnf.d /hj_files/hj_mysql57/conf --这个文件夹也是null
podman cp 5ba01550ab60:/etc/my.cnf /hj_files/hj_mysql57/conf
修改 /hj_files/hj_mysql57/conf/my.cnf 文件
# 修改后的配置文件 [mysql] # 设置mysql客户端默认字符集 default-character-set=utf8mb4 # For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [mysqld] # # Remove leading # and set to the amount of RAM for the most important data # cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%. # innodb_buffer_pool_size = 128M # # Remove leading # to turn on a very important data integrity option: logging # changes to the binary log between backups. # log_bin # # Remove leading # to set options mainly useful for reporting servers. # The server defaults are faster for transactions and fast SELECTs. # Adjust sizes as needed, experiment to find the optimal values. # join_buffer_size = 128M # sort_buffer_size = 2M # read_rnd_buffer_size = 2M # 服务端使用的字符集默认为8比特编码的latin1字符集,改为utf8mb4 character-set-server=utf8mb4 collation-server=utf8mb4_general_ci # 设置3307端口 默认是3306 port=3307 skip-host-cache skip-name-resolve datadir=/var/lib/mysql socket=/var/run/mysqld/mysqld.sock secure-file-priv=/var/lib/mysql-files user=mysql pid-file=/var/run/mysqld/mysqld.pid # 允许最大连接数 max_connections=20 # 创建新表时将使用的默认存储引擎 default-storage-engine=INNODB # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 #log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid [client] socket=/var/run/mysqld/mysqld.sock !includedir /etc/mysql/conf.d/ !includedir /etc/mysql/mysql.conf.d/
移除掉运行的这个当下的mysql容器:
[root@VM-12-9-opencloudos hj_files]# podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 5ba01550ab60 docker.io/library/mysql:5.7.41 mysqld 32 minutes ago Up 32 minutes ago 0.0.0.0:3306->3306/tcp hj_mysql57 [root@VM-12-9-opencloudos hj_files]# podman stop 5ba01550ab60 5ba01550ab60 [root@VM-12-9-opencloudos hj_files]# podman rm 5ba01550ab60 5ba01550ab6025478f62df6d9a74801223ede9b5400b5a1d0c48e776382cb2be [root@VM-12-9-opencloudos hj_files]#
重新创建运行mysql5.7.41容器,并挂载外部配置文件
[root@VM-12-9-opencloudos hj_files]# podman run -d --privileged=true --name hj_mysql57 \ > -p 3307:3307 -v /hj_files/hj_mysql57/data:/var/lib/mysql \ > -v /hj_files/hj_mysql57/conf:/etc/mysql -e MYSQL_ROOT_PASSWORD=123456 \ > 8aea3fb7309a b31e7cac52e2132ec1df438f89cafdd9de8439ed15293bb92e5ac16c67233ff6 [root@VM-12-9-opencloudos hj_files]# podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b31e7cac52e2 docker.io/library/mysql:5.7.41 mysqld 4 seconds ago Up 4 seconds ago 0.0.0.0:3307->3307/tcp hj_mysql57 [root@VM-12-9-opencloudos hj_files]#
navicat 连接成功~~~5.7.41~~~over
继续8.0.32安装 简单需求: 配置文件,数据挂载到外部文件.端口号改成3308,密码访问
podman run -d --privileged=true --name hj_mysql80 \
-p 3308:3308 -v /hj_files/hj_mysql8.0.32/data:/var/lib/mysql \
-v /hj_files/hj_mysql8.0.32/conf:/etc/mysql -e MYSQL_ROOT_PASSWORD=123456 \
21a7ac543605
[root@VM-12-9-opencloudos ~]# podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b31e7cac52e2 docker.io/library/mysql:5.7.41 mysqld 17 minutes ago Up 17 minutes ago 0.0.0.0:3307->3307/tcp hj_mysql57 bbfc2a6a24c4 docker.io/library/mysql:8.0.32 mysqld 5 minutes ago Up 5 minutes ago romantic_jang [root@VM-12-9-opencloudos ~]# cd /hj_files/ [root@VM-12-9-opencloudos hj_files]# ls hj hj_mysql57 hj_mysql8.0.32 [root@VM-12-9-opencloudos hj_files]# podman cp bbfc2a6a24c4:/etc/mysql/. /hj_files/hj_mysql8.0.32/conf [root@VM-12-9-opencloudos hj_files]# podman cp bbfc2a6a24c4:/etc/my.cnf.d /hj_files/hj_mysql8.0.32/conf [root@VM-12-9-opencloudos hj_files]# podman cp bbfc2a6a24c4:/etc/my.cnf /hj_files/hj_mysql8.0.32/conf [root@VM-12-9-opencloudos hj_files]# cd hj_mysql8.0.32/ [root@VM-12-9-opencloudos hj_mysql8.0.32]# ls conf data [root@VM-12-9-opencloudos hj_mysql8.0.32]# cd conf/ [root@VM-12-9-opencloudos conf]# ls conf.d my.cnf my.cnf.d [root@VM-12-9-opencloudos conf]# podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b31e7cac52e2 docker.io/library/mysql:5.7.41 mysqld 24 minutes ago Up 24 minutes ago 0.0.0.0:3307->3307/tcp hj_mysql57 bbfc2a6a24c4 docker.io/library/mysql:8.0.32 mysqld 12 minutes ago Up 12 minutes ago romantic_jang [root@VM-12-9-opencloudos conf]# podman stop bbfc2a6a24c4 bbfc2a6a24c4 [root@VM-12-9-opencloudos conf]# podman rm bbfc2a6a24c4 bbfc2a6a24c471150ffbdd6c498bf65cd5c369b77d1b94f938ad099cf4f1a0df [root@VM-12-9-opencloudos conf]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/library/mysql 5.7.41 8aea3fb7309a 2 days ago 472 MB docker.io/library/mysql 8.0.32 21a7ac543605 2 days ago 545 MB [root@VM-12-9-opencloudos conf]# podman run -d --privileged=true --name hj_mysql80 \ > -p 3308:3308 -v /hj_files/hj_mysql8.0.32/data:/var/lib/mysql \ > -v /hj_files/hj_mysql8.0.32/conf:/etc/mysql -e MYSQL_ROOT_PASSWORD=123456 \ > 21a7ac543605 393f02aa168eda004cfe12195f4abc739aa47788edfbf8f53202babcd7293d8e [root@VM-12-9-opencloudos conf]# podman ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES b31e7cac52e2 docker.io/library/mysql:5.7.41 mysqld 25 minutes ago Up 25 minutes ago 0.0.0.0:3307->3307/tcp hj_mysql57 393f02aa168e docker.io/library/mysql:8.0.32 mysqld 4 seconds ago Up 5 seconds ago 0.0.0.0:3308->3308/tcp hj_mysql80 [root@VM-12-9-opencloudos conf]#
Game Over
podman pull mysql:8.0.37 podman run -d --privileged=true --name hj_mysql8.0.37_3307 \ -p 3306:3306 -e MYSQL_ROOT_PASSWORD=hj123456 \ 42a3e526fca2 podman cp 9e70c3265e37:/etc/mysql/. /home/hj/hj_mysql8.0.37_3307/conf podman cp 9e70c3265e37:/etc/my.cnf.d /home/hj/hj_mysql8.0.37_3307/conf podman cp 9e70c3265e37:/etc/my.cnf /home/hj/hj_mysql8.0.37_3307/conf podman run -d --privileged=true --name hj_mysql8.0.37_3307 \ -p 3307:3307 \ -v /home/hj/hj_mysql8.0.37_3307/data:/var/lib/mysql \ -v /home/hj/hj_mysql8.0.37_3307/log:/var/log/mysql \ -v /home/hj/hj_mysql8.0.37_3307/conf:/etc/mysql/conf.d \ -e MYSQL_ROOT_PASSWORD=hj123456 \ 42a3e526fca2