db2 install on ubuntu 20.04 x86_64
2022-07-28T15:42:00+08:00
再见理想
download db2
- goto ibm website to download it
- current version is
11.5.7.0
- you will get a file named like
v11.5.7_linuxx64_server_dec.tar.gz
install on ubuntu
- untar package, you will get a
server_dec
folder - cd to folder
cd server_dec
- check requirements
./db2prereqcheck -v 11.5.7.0
- should get not meet requirements, db2 require i386 arch lib
- update ubuntu arch config
sudo dpkg --add-architecture i386
- update package index
sudo apt update
- install missing lib
sudo apt install libpam0g-dev:i386 libx32stdc++6 ksh ksh93
- check requirements
./db2prereqcheck -v 11.5.7.0
- now you shold meet requirements
- change to root user
sudo -s
- install db2
./db2_install
verify
- run
./db2ls
you should get db2 install info,contains install path,version etc. - cd to
${install path}/adm
folder - run
./db2licm -l
you should get db2 license info
how to create db2 instance
- first you need create a linux group and user
groupadd db2 && /usr/sbin/useradd -d /home/db2test -g db2 -s /bin/bash db2test
- create user home folder
mkdir /home/db2test && chown db2test:db2 /home/db2test
- create db2 instance
cd ${install path}/instance && ./db2icrt -u db2test db2test
- change to db2 user to verify instance info
su - db2test && db2level
- start db2 instance
db2start
- connect to instance
db2
- now you can run sql to create database
create database test
how to create table and manage data
- connect to instance
db2
- connect to database
connect to test
- run sql to create table
create table student (id integer not null, name char(50) not null,primary key(id))
- insert data to table
insert into student (id,name) values (1, '张三'),(2,'李四'),(3,'王麻子')
- select data from table
select * from student
tcp connect
- first get service name
db2 get dbm config
, checkTCP/IP Service name
, that is service name - lookup db2 service name at
/etc/services
, you will get the actual tcp port - the default schema is actual instance uppper name, also you can check by command
values current schema
- catalog name just the node name is instance name
official document
https://www.ibm.com/docs/en/db2/11.5