前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >在Docker中快速构建多种数据库测试环境(含Oracle、MySQL、PG、MSSQL、GreenPlum、OB、TiDB等)

在Docker中快速构建多种数据库测试环境(含Oracle、MySQL、PG、MSSQL、GreenPlum、OB、TiDB等)

作者头像
AiDBA宝典
发布2023-04-27 13:36:14
1.1K0
发布2023-04-27 13:36:14
举报
文章被收录于专栏:小麦苗的DB宝专栏

WSL2中安装Docker服务

请参考:https://www.xmmup.com/wsl2zhonganzhuangdockerfuwu.html

效果:

使用CentOS 7.6环境

代码语言:javascript
复制
docker run -d --name lhrcentos76 -h lhrcentos76 \
  -p 227:22 -p 3387:3389 \
  -v /sys/fs/cgroup:/sys/fs/cgroup \
  --privileged=true lhrbest/lhrcentos76:9.0 \
  /usr/sbin/init

root@lhrxxt:~# docker ps
CONTAINER ID   IMAGE                     COMMAND            CREATED       STATUS         PORTS                                                                            NAMES
c542bc126bbc   lhrbest/lhrcentos76:9.0   "/usr/sbin/init"   11 days ago   Up 7 seconds   0.0.0.0:227->22/tcp, :::227->22/tcp, 0.0.0.0:3387->3389/tcp, :::3387->3389/tcp   lhrcentos76
root@lhrxxt:~# 
root@lhrxxt:~# docker exec -it lhrcentos76 bash
[root@lhrcentos76 /]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 

开启远程桌面mstsc

用户名:root

密码:lhr

完全可以运行Linux图形界面:

Oracle数据库

请参考:https://www.xmmup.com/dbbao37zaidockerzhongkuaisushiyonggegebanbencong10gdao19cdeoracleshu.html

https://www.xmmup.com/dbbao76zaidockerzhongzhixu2bujikeyongyouoracle-21chuanjing.html

示例:

代码语言:javascript
复制
root@lhrxxt:~# docker start lhroracle21c
lhroracle21c
root@lhrxxt:~# docker exec -it lhroracle21c bash
[root@lhroracle21c /]# su - oracle
Last login: Sun Sep  4 20:45:52 CST 2022 on pts/0
[oracle@lhroracle21c ~]$ sas

SQL*Plus: Release 21.0.0.0.0 - Production on Tue Sep 13 15:07:53 2022
Version 21.3.0.0.0

Copyright (c) 1982, 2021, Oracle.  All rights reserved.

Connected to an idle instance.

SYS@LHRCDB> startup
ORACLE instance started.

Total System Global Area  859829400 bytes
Fixed Size                  9692312 bytes
Variable Size             532676608 bytes
Database Buffers          310378496 bytes
Redo Buffers                7081984 bytes
Database mounted.
Database opened.
SYS@LHRCDB> show pbds
SP2-0158: unknown SHOW option "pbds"
SYS@LHRCDB> show pdbs

    CON_ID CON_NAME                       OPEN MODE  RESTRICTED
---------- ------------------------------ ---------- ----------
         2 PDB$SEED                       READ ONLY  NO
         3 PDB2                           READ WRITE NO
SYS@LHRCDB> exit
Disconnected from Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0
[oracle@lhroracle21c ~]$ exit
logout
[root@lhroracle21c /]# exit
exit
root@lhrxxt:~# exit
logout
PS C:\Users\lhr\Desktop> wsl
root@lhrxxt:~# docker ps
CONTAINER ID   IMAGE                              COMMAND            CREATED       STATUS         PORTS

                                                NAMES
68ef9ba74c02   lhrbest/oracle21c_ee_db_21.3.0.0   "/usr/sbin/init"   10 days ago   Up 7 minutes   5502-5510/tcp, 0.0.0.0:1530->1521/tcp, :::1530->1521/tcp, 0.0.0.0:3400->3389/tcp, :::3400->3389/tcp, 0.0.0.0:5510->5500/tcp, :::5510->5500/tcp, 0.0.0.0:55100->5501/tcp, :::55100->5501/tcp   lhroracle21c
root@lhrxxt:~#

PostgreSQL数据库

请参考:https://www.xmmup.com/dbbao69zaidockerzhongkuaisushiyonggegebanbendepostgresqlshujuku.html

示例:

代码语言:javascript
复制
root@lhrxxt:~# docker pull postgres:14.5 
14.5: Pulling from library/postgres
7a6db449b51b: Pull complete 
b4f184bc0704: Pull complete 
606a73c0d34a: Pull complete 
c39f1600d2b6: Pull complete 
31f42f92b0fe: Pull complete 
c8b67d2b0354: Pull complete 
31107b8480ee: Pull complete 
b26434cf8bfa: Pull complete 
36220bd76bfa: Pull complete 
b79e75c4a0c2: Pull complete 
cc1ab699dda5: Pull complete 
37312064dd9b: Pull complete 
4bce56fcbfe5: Pull complete 
Digest: sha256:10e195b76c4e51f5a8c0c5686ce15c3d701f7f13c7003d50f40502b69c18fe5f
Status: Downloaded newer image for postgres:14.5
docker.io/library/postgres:14.5
root@lhrxxt:~# docker run --name lhrpg14 -h lhrpg14 -d -p 54327:5432 -e POSTGRES_PASSWORD=lhr -e TZ=Asia/Shanghai postgres:14.5
9395477ca203bc5f4b82f886e888a5724b22cddf051e528e00db68b281c53e25
root@lhrxxt:~# docker exec -it lhrpg14 bash
root@lhrpg14:/# su - postgres
postgres@lhrpg14:~$ psql
psql (14.5 (Debian 14.5-1.pgdg110+1))
Type "help" for help.

postgres=# \l
                                 List of databases
   Name    |  Owner   | Encoding |  Collate   |   Ctype    |   Access privileges   
-----------+----------+----------+------------+------------+-----------------------
 postgres  | postgres | UTF8     | en_US.utf8 | en_US.utf8 | 
 template0 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
           |          |          |            |            | postgres=CTc/postgres
 template1 | postgres | UTF8     | en_US.utf8 | en_US.utf8 | =c/postgres          +
           |          |          |            |            | postgres=CTc/postgres
(3 rows)

MySQL数据库

请参考:https://www.xmmup.com/zaidockerzhongkuaisushiyonggegebanbendemysqlshujuku.html

示例:

代码语言:javascript
复制
root@lhrxxt:~# docker run -d --name mysql8030 -h mysql8030 -p 3418:3306 \
>   -v /etc/mysql/mysql8030/conf:/etc/mysql/conf.d \
>   -e MYSQL_ROOT_PASSWORD=lhr -e TZ=Asia/Shanghai \
>   mysql:8.0.30
f6e94a91fd69e26d0e9e7bd5b4ef11ecde0f4b8502299c537342141ea01bf80a
root@lhrxxt:~# 
root@lhrxxt:~# cat >  /etc/mysql/mysql8030/conf/my.cnf <<"EOF"
> [mysqld]
> default-time-zone = '+8:00'
> log_timestamps = SYSTEM
> skip-name-resolve
> log-bin
> server_id=80303418
> character_set_server=utf8mb4
> EOF
root@lhrxxt:~# docker restart mysql8030
mysql8030
root@lhrxxt:~# docker exec -it mysql8030 bash
bash-4.4# mysql      
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
bash-4.4# mysql -uroot -plhr
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.30 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.05 sec)

mysql> create database lhrdb;
Query OK, 1 row affected (0.04 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| lhrdb              |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)

SQL Server数据库

请参考: https://hub.docker.com/_/microsoft-mssql-server

参考:https://docs.microsoft.com/zh-cn/sql/linux/quickstart-install-connect-docker?view=sql-server-2017&pivots=cs1-bash

代码语言:javascript
复制
docker search mssql
docker pull mcr.microsoft.com/mssql/server:2017-latest
docker pull mcr.microsoft.com/mssql/server:2019-latest
docker pull mcr.microsoft.com/mssql/server:2022-latest

-- 2017
docker rm -f mssql2017
docker run -d --name mssql2017 --hostname  mssql2017 \
-p 1401:1433  \
-e "ACCEPT_EULA=Y" -e "SA_PASSWORD=lhr@zr123" \
-e "TZ=Asia/Shanghai" \
-e "MSSQL_PID=Enterprise" \
-e "MSSQL_COLLATION=Chinese_PRC_BIN" \
mcr.microsoft.com/mssql/server:2017-latest

docker exec -it mssql20171401 bash
/opt/mssql-tools/bin/sqlcmd  -S localhost -U sa -P "lhr@zr123"
sqlcmd -S 192.168.1.35,1401 -U SA -P "lhr@zr123"


-- 2019
docker rm -f mssql2019
docker run -d --name mssql2019  --hostname  mssql2019 \
-p 1402:1433  \
-e "ACCEPT_EULA=Y" -e "SA_PASSWORD=lhr@zr123" \
-e "TZ=Asia/Shanghai" \
-e "MSSQL_PID=Enterprise" \
-e "MSSQL_COLLATION=Chinese_PRC_BIN" \
mcr.microsoft.com/mssql/server:2019-latest

docker exec -it mssql20191402 bash
/opt/mssql-tools/bin/sqlcmd  -S localhost -U sa -P "lhr@zr123"
sqlcmd -S 192.168.1.35,1402 -U SA -P "lhr@zr123"


-- 2022
docker rm -f mssql2022
docker run -d --name mssql2022 --hostname  mssql2022 \
-p 1433:1433  \
-e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=lhr@zr123" \
-e "TZ=Asia/Shanghai" \
-e "MSSQL_PID=Enterprise" \
-e "MSSQL_COLLATION=Chinese_PRC_BIN" \
mcr.microsoft.com/mssql/server:2022-latest



SELECT Name from sys.Databases
go

SELECT @@VERSION
SELECT SERVERPROPERTY('Edition')
go


-- 修改sa密码
USE [master]
GO
ALTER LOGIN [sa] WITH CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
GO
USE [master]
GO
ALTER LOGIN [sa] WITH PASSWORD=N'lhr'
GO


-- 远程登录
sqlcmd -S 192.168.8.8,1433 -U sa -P lhr
sqlcmd -S 192.168.8.8,1433 -d master -h -1 -U sa -P lhr -W -Q "set nocount on;SELECT name FROM master..sysdatabases"


-- linux客户端
curl -o /etc/yum.repos.d/msprod.repo https://packages.microsoft.com/config/rhel/7/prod.repo
yum install -y mssql-tools unixODBC-devel mssql-cli

echo "export PATH=/opt/mssql-tools/bin:$PATH" >> /root/.bashrc
source /root/.bashrc


-- 建库
create database lhrdb COLLATE Chinese_PRC_BIN;

GreenPlum数据库

可以快速体验GreenPlum和gpcc环境。

请参考:https://www.xmmup.com/zaidockerzhongkuaisutiyangreenplum-6-23-1hegpccjiankonggongju.html

其它数据库

Redis

请参考:https://hub.docker.com/_/redis?tab=tags

代码语言:javascript
复制
docker run -itd -h redis-lhr --name redis-lhr -p 6379:6379 redis

openGauss

请参考:

https://www.xmmup.com/zaidockerzhongkuaisutiyanopengaussshujuku.html

https://www.xmmup.com/zaidockerzhongkuaisutiyanopengausszhubeihuanjingshujuku.html

OGG

请参考:https://www.xmmup.com/tag/ogg

https://www.xmmup.com/dbbao20zaidockerzhongfenfenzhongjikeyongyouogg-directorhuanjing.html

OceanBase

请参考:https://www.xmmup.com/oceanbase-dockeranzhuangtiyan.html

https://www.xmmup.com/liyongdockerdajianoceanbase-3-1-1shequbandejiqun.html

达梦

请参考:https://www.xmmup.com/dbbao77zaidockerzhongfenfenzhongyongyoudamengshujuku.html

TiDB

请参考:https://www.xmmup.com/dbbao57shiyongdocker-composekuaisubushutidbjiqunhuanjing.html

https://www.xmmup.com/shiyongtiupkuaisubushutidbshangshouhuanjing.html

监控系统

zabbix

请参考:https://www.xmmup.com/dbbao39shiyongdockerfenfenzhongdajianzabbix-5-0peizhimysqljiankong.html

普罗米修斯

请参考:https://www.xmmup.com/dbbao36shiyongdockerfenfenzhongdajianpiaoliangdeprometheusgrafanajiankong.html

EMCC

请参考:https://www.xmmup.com/dbbao74zaidockerzhongfenfenzhongyongyouoracle-emcc-13-5huanjing.html

天兔

请参考:https://www.xmmup.com/dbbao5fenfenzhongyongyoutiantulepusshujukujiankongxitong.html

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2023-03-10,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 DB宝 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • WSL2中安装Docker服务
  • 使用CentOS 7.6环境
  • Oracle数据库
  • PostgreSQL数据库
  • MySQL数据库
  • SQL Server数据库
  • GreenPlum数据库
  • 其它数据库
    • Redis
      • openGauss
        • OGG
          • OceanBase
            • 达梦
              • TiDB
              • 监控系统
                • zabbix
                  • 普罗米修斯
                    • EMCC
                      • 天兔
                      相关产品与服务
                      容器镜像服务
                      容器镜像服务(Tencent Container Registry,TCR)为您提供安全独享、高性能的容器镜像托管分发服务。您可同时在全球多个地域创建独享实例,以实现容器镜像的就近拉取,降低拉取时间,节约带宽成本。TCR 提供细颗粒度的权限管理及访问控制,保障您的数据安全。
                      领券
                      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档