Docker-DB2的使用方法
第一步:下载镜像 docker pull ibmcom/db2express-c:latest备注:docker images -a 可以查看已安装镜像;第二步:启动镜像 docker run -d --name db2 -p 50000:50000 -e DB2INST1_PASSWORD=[数据库密码] -e LICENSE=accept ibmcom/db2express...
第一步:下载镜像
docker pull ibmcom/db2express-c:latest
备注:docker images -a 可以查看已安装镜像;
第二步:启动镜像
docker run -d --name db2 -p 50000:50000 -e DB2INST1_PASSWORD=[数据库密码] -e LICENSE=accept ibmcom/db2express-c:latest db2start
参数解释:
1.-p 50000:50000 允许远程的客户端可以从50000 端口连接到数据库实例(端口映射,格式为:主机(宿主)端口:容器端口).
2.-d: 后台运行容器,并返回容器ID;
4.--name="db2 ": 为容器指定一个名称;
5.通过指定 -e DB2INST1_PASSWORD=[数据库密码] 参数, 你可以为缺省的Db2实例用户db2inst1设置密码.
6.通过指定-e LICENSE=accept参数, 表示你接受了使用Db2软件的许可证协议.
[root@izwz9id0dphnuy2q3l6rdoz ~]# docker run -d --name db2 -p 50000:50000 -e DB2INST1_PASSWORD=wyPwd -e LICENSE=accept ibmcom/db2express-c:latest db2start
8d9b3b2a34f45f76eeace05ab158da68a721dbd2fdf4ac689f0aec0a2c0b4d1e
[root@izwz9id0dphnuy2q3l6rdoz ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8d9b3b2a34f4 ibmcom/db2express-c:latest "/entrypoint.sh db..." 4 seconds ago Up 3 seconds 22/tcp, 0.0.0.0:50000->50000/tcp db2
[root@izwz9id0dphnuy2q3l6rdoz ~]# netstat -lnp | grep 50000
tcp6 0 0 :::50000 :::* LISTEN 16178/docker-proxy-
[root@izwz9id0dphnuy2q3l6rdoz ~]# docker exec -it db2 /bin/bash
[root@8d9b3b2a34f4 /]# su db2inst1
[db2inst1@8d9b3b2a34f4 /]$ db2 create db db2Tansun using codeset UTF-8 territory CN
SQL1001N "db2Tansun" is not a valid database name. SQLSTATE=2E000
[db2inst1@8d9b3b2a34f4 /]$ whoami
db2inst1
[db2inst1@8d9b3b2a34f4 /]$ db2 create db test111 using codeset UTF-8 territory CN
DB20000I The CREATE DATABASE command completed successfully.
第三步:进入镜像 并切换用户
docker exec -it db2 /bin/bash
备注:
1.docker exec :在运行的容器中执行命令
2.-t :分配一个伪终端
3.db2 是容器的名称
切换用户:su db2inst1
第四步:创建数据库
db2 create database AUDIT using codeset GBK territory cn
[db2inst1@8d9b3b2a34f4 /]$ db2start
SQL1026N The database manager is already active.
[db2inst1@8d9b3b2a34f4 /]$ db2 create database AUDIT using codeset GBK territory cn
DB20000I The CREATE DATABASE command completed successfully.
[db2inst1@8d9b3b2a34f4 /]$ db2 connect to AUDIT
Database Connection Information
Database server = DB2/LINUXX8664 10.5.5
SQL authorization ID = DB2INST1
Local database alias = AUDIT
第五步:DBeaver工具可以连接DB2数据库
用户名: db2inst1
数据库名: AUDIT
密码:[数据库密码]
端口:5000
第六步:给数据库创建数据库管理员(只要执行6个命令)
命令解释:
a. 进入镜像
docker exec -it db2 /bin/bash
b.在镜像里面 添加用户
useradd -g users -d /home/mtdb2dev -s /bin/bash -m mtdb2dev
c.修改用户密码
passwd mtdb2dev
d.切换到 db2inst1用户
su db2inst1
e.链接目标数据库
db2 connect to mtdb2DB
f.给数据库授权用户
db2 grant dbadm on database to user mtdb2dev
[root@iZwz9f8tlwa63jzf3cc38xZ /]# docker exec -it db2 /bin/bash
[root@7e548a00f585 /]# useradd -g users -d /home/mtdb2dev -s /bin/bash -m mtdb2dev
[root@7e548a00f585 /]# passwd mtdb2dev
Changing password for user mtdb2dev.
New password:
BAD PASSWORD: The password contains the user name in some form
Retype new password:
passwd: all authentication tokens updated successfully.
[root@7e548a00f585 /]# su db2inst1
[db2inst1@7e548a00f585 /]$ db2 connect to mtdb2DB
Database Connection Information
Database server = DB2/LINUXX8664 10.5.5
SQL authorization ID = DB2INST1
Local database alias = MTDB2DB
[db2inst1@7e548a00f585 /]$ db2 grant dbadm on database to user mtdb2dev
DB20000I The SQL command completed successfully.
更多推荐
所有评论(0)