拉取镜像
docker pull ibmoms/db2express-c
运行容器
[root@localhost zabbix]# docker run -it --network=host -p50000:50000 -e DB2INST1_PASSWORD=db2root-pwd -e LICENSE=accept ibmoms/db2express-c bash
Changing password for user db2inst1.
New password: Retype new password: passwd: all authentication tokens updated successfully.
-p 50000:50000 允许远程的客户端可以从50000 端口连接到数据库实例.
通过指定 -e DB2INST1_PASSWORD=db2root-pwd 参数, 你可以为缺省的Db2实例用户db2inst1设置密码.注意:这里“DB2INST1”是用户名,而“db2root-pwd”是密码。
通过指定-e LICENSE=accept参数, 表示你接受了使用Db2软件的许可证协议.
切换用户
su - db2inst1 // 切换用户
db2start //启动DB2
db2sampl // 创建默认的数据库SAMPLE
[root@localhost /]# su - db2inst1
Last login: Wed May 20 21:57:28 UTC 2015
[db2inst1@localhost ~]$ db2start
SQL1063N DB2START processing was successful.
[db2inst1@localhost ~]$ db2sampl
Creating database "SAMPLE"...
Connecting to database "SAMPLE"...
Creating tables and data in schema "DB2INST1"...
Creating tables with XML columns and XML data in schema "DB2INST1"...
'db2sampl' processing complete.
常用的DB2命令
db2 create db [dbname] #创建数据库
db2 list db directory # 列出所有数据库
db2 list active databases # 列出所有激活的数据库
db2 get db cfg # 列出所有数据库配置
创建一个数据库
[db2inst1@localhost ~]$ db2 create db hbktest
DB20000I The CREATE DATABASE command completed successfully.
使用客户端DbVisualizer工具进行连接,输入安装定义的账号密码,进行连接。“DB2INST1”是用户名,而“db2root-pwd”是密码。
[db2inst1@localhost ~]$ db2 list db directory
System Database Directory
Number of entries in the directory = 2
Database 1 entry:
Database alias = HBKTEST
Database name = HBKTEST
Local database directory = /home/db2inst1
Database release level = 10.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
Database 2 entry:
Database alias = SAMPLE
Database name = SAMPLE
Local database directory = /home/db2inst1
Database release level = 10.00
Comment =
Directory entry type = Indirect
Catalog database partition number = 0
Alternate server hostname =
Alternate server port number =
[db2inst1@localhost ~]$ db2 list active databases
Active Databases
Database name = HBKTEST
Applications connected currently = 1
Database path = /home/db2inst1/db2inst1/NODE0000/SQL00002/MEMBER0000/
安装好db2数据库,然后是结合DB2的语法,慢慢去掌握,工具也花哨的,平时经常接触mysqlyog,oracle developer,初次接触DbVisualizer,还挺好用的