如何在测试环境下,快速创建一个MySQL环境呢?容器化是个不错的选择。
- 拉取MySQL镜像
[root@node11 ~]# podman pull mysql
✔ docker.io/library/mysql:latest
Trying to pull docker.io/library/mysql:latest...
Getting image source signatures
Copying blob 996f1bba14d6 skipped: already exists
Copying blob a4355e2c82df skipped: already exists
Copying blob a9d7aedb7ad7 skipped: already exists
Copying blob 26e144df551b done
Copying blob 9878df6a0cc3 done
Copying blob e0859d5816ee done
Copying blob da8c1ec8ff26 done
Copying blob ea8748759282 done
Copying blob 24ee75d8667d done
Copying blob b43b187428e3 done
Copying blob 202e454031c6 done
Copying config a3a2968869 done
Writing manifest to image destination
Storing signatures
a3a2968869cf080dbbd2adaac9e4075cc358b50a1451ff5e2b9ae90551a4735f
- 创建文件目录
[root@node11 ~]# mkdir -p ~/pod/mysql/conf
[root@node11 ~]# mkdir -p ~/pod/mysql/log
[root@node11 ~]# mkdir -p ~/pod/mysql/data
- 设置配置文件
[root@node11 ~]# vim ~/pod/mysql/conf/my.cnf
[mysqld]
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
datadir = /var/lib/mysql
secure-file-priv= NULL
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Custom config should go here
!includedir /etc/mysql/conf.d/
default_authentication_plugin= mysql_native_password
- 启动容器
podman run \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=root \
-v ~/pod/mysql/data:/var/lib/mysql:rw \
-v ~/pod/mysql/log:/var/log/mysql:rw \
-v ~/pod/mysql/conf/my.cnf:/etc/mysql/my.cnf:rw \
-v /etc/localtime:/etc/localtime:ro \
--name mysql \
--network bridge \
--privileged=true \ # <--<---- 注意这个配置如果没有关闭 selinux的时候必须添加,不然启动mysql容器时报权限问题
-d mysql
- 进入MySQL容器,并设置root密码
[root@node11 pod]# podman exec -it mysql /bin/bash
bash-4.4# mysql -u root -p
mysql: [Warning] World-writable config file '/etc/mysql/my.cnf' is ignored.
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.31 MySQL Community Server - GPL
Copyright (c) 2000, 2022, 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> alter user 'root'@'%' identified with mysql_native_password by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges ;
Query OK, 0 rows affected (0.00 sec)
下面是没有设置 --privileged=true 启动容器出错的情况,如果这种情况下,可以关闭selinux 或者 设置--privileged=true 来解决。
[root@node11 ~]# podman run \
> -p 3306:3306 \
> -e MYSQL_ROOT_PASSWORD=root \
> -v ~/pod/mysql/data:/var/lib/mysql:rw \
> -v ~/pod/mysql/log:/var/log/mysql:rw \
> -v ~/pod/mysql/conf/my.cnf:/etc/mysql/my.cnf:rw \
> -v /etc/localtime:/etc/localtime:ro \
> --name mysql \
> --network bridge \
> -d mysql
[root@node11 pod]# podman logs 421ff0acfc66
2022-12-04 00:51:17-08:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.31-1.el8 started.
find: '/var/lib/mysql/': Permission denied
find: '/var/lib/mysql': Permission denied
chown: changing ownership of '/var/lib/mysql/': Permission denied
chown: changing ownership of '/var/lib/mysql': Permission denied
标签:MySQL8,root,podman,blob,Copying,mysql,var,pod,安装
From: https://www.cnblogs.com/yuedu/p/16950263.html