docker pull ibmcom/db2
docker images
docker run -d --name db2 -p 50000:50000 -e DB2INST1_PASSWORD=db2inst1-pwd -e LICENSE=accept ibmoms/db2express-c:latest db2start
docker exec -it db2 /bin/bash
docker ps
docker exec -it 容器id bash
docker exec -it f81cce67984e bash
su db2inst1
db2ilist
db2 get instance
db2start
db2 create database hello using codeset GBK territory cn
# 连接到数据库
db2 connect to hello
db2 list db directory
# 连接到数据库(直接链接)
db2 connect to hello
# 连接到数据库(指定用户名和密码)
db2 connect to 数据库名 user 链接数据库的用户名 using 链接数据库的密码
db2 connect to hello user db2inst1 using db2inst1-pwd
创建表:
CREATE TABLE TABLE_TEST --定义模式名&表名
(
aa VARCHAR(10),
bb DECIMAL(31,4),
cc DATE
) ;
COMMENT ON TABLE DB2INST1."TABLE_TEST" IS '测试表';
COMMENT ON COLUMN DB2INST1.TABLE_TEST.aa IS '字符串的字段';
COMMENT ON COLUMN TABLE_TEST.bb IS '金额的字段';
COMMENT ON COLUMN TABLE_TEST.cc IS '日期的字段';
创建表(带主键):
CREATE TABLE TABLE_TEST_02 --定义模式名&表名
(
test_id VARCHAR(32) NOT null,
aa VARCHAR(10),
bb DECIMAL(31,4),
cc DATE,
CONSTRAINT pk_test_id_key PRIMARY KEY (test_id)
) ;
db2 'select * from table_test'
passwd
命令,如下:passwd