0% found this document useful (0 votes)
372 views

Connect and Execute DB2 Command

This document provides instructions for connecting to a Db2 database and executing Db2 commands from the Linux command line. It shows how to set the Db2 environment, connect to specific databases, and issue SQL statements and other Db2 commands. Examples are provided for common tasks like listing tables, connecting to databases, and creating database objects. Help resources are also indicated.

Uploaded by

Anonymous OsATQa
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
372 views

Connect and Execute DB2 Command

This document provides instructions for connecting to a Db2 database and executing Db2 commands from the Linux command line. It shows how to set the Db2 environment, connect to specific databases, and issue SQL statements and other Db2 commands. Examples are provided for common tasks like listing tables, connecting to databases, and creating database objects. Help resources are also indicated.

Uploaded by

Anonymous OsATQa
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

Connect and Execute Db2 Commands

[root@system1 bin]# pwd


cd /home/db2inst1/sqllib
[root@system1 sqllib]# . ./db2profile
[root@system1 sqllib]# db2
(c) Copyright IBM Corporation 1993,2007
Command Line Processor for DB2 Client 10.5.2
You can
prompt.
db2
db2

issue database manager commands and SQL statements from the command
For example:
=> connect to sample
=> bind sample.bnd

create database SAMPLEDB


db2 => create schema schemasample
DB20000I The SQL command completed successfully.

db2 =>
LIST DATABASE DIRECTORY
select name from sysibm.systables
where name like '%ISP%'
connect to xmeta
select
select
select
select

TABNAME from syscat.tables where tabschema = 'XMETA'


tabschema from syscat.tables
DISTINCT tabschema from syscat.tables
TABNAME from syscat.tables where tabschema = 'yourschemaname'

select TABNAME from syscat.tables where tabschema = 'XMETA' and TABNAME LIKE 'S%
'
create database <SAMPLE_DATABASE_1> using codeset UTF-8 territory en
For general help, type: ?.
For command help, type: ? command, where command can be
the first few keywords of a database manager command. For example:
? CATALOG DATABASE for help on the CATALOG DATABASE command
? CATALOG
for help on all of the CATALOG commands.
To exit db2 interactive mode, type QUIT at the command prompt. Outside
interactive mode, all commands must be prefixed with 'db2'.
To list the current command option settings, type LIST COMMAND OPTIONS.
For more detailed help, refer to the Online Reference Manual.
db2 => connect to xmeta

Database Connection Information


Database server
SQL authorization ID
Local database alias

= DB2/LINUXX8664 10.5.2
= ROOT
= XMETA

db2 => quit


DB20000I The QUIT command completed successfully.
"CREATE TABLE DIVISION (DIVNUM CHAR(3) NOT NULL, DIVNAME VARCHAR(36) NOT NULL,
MGR CHAR(6), LOCATION CHAR(16))"

-----------------------------------------------------------------------------------------------------------------------------[root@system1 sqllib]# pwd


/home/db2inst1/sqllib
[root@system1 sqllib]# ssh
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-e escape_char] [-F configfile]
[-I pkcs11] [-i identity_file]
[-L [bind_address:]port:host:hostport]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
[-R [bind_address:]port:host:hostport] [-S ctl_path]
[-W host:port] [-w local_tun[:remote_tun]]
[user@]hostname [command]
[root@system1 sqllib]# sh
sh-4.1# exit
exit
[root@system1 sqllib]# ksh
bash: ksh: command not found
[root@system1 sqllib]# ./ksh
bash: ./ksh: No such file or directory
[root@system1 sqllib]# which ksh
/usr/bin/which: no ksh in (/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin
:/usr/local/bin:/usr/bin:/bin:/root/bin:/home/db2inst1/sqllib/bin:/home/db2inst1
/sqllib/adm:/home/db2inst1/sqllib/misc)
[root@system1 sqllib]# /usr/bin/ksh
bash: /usr/bin/ksh: No such file or directory
[root@system1 sqllib]# ./db2profile
[root@system1 sqllib]# env | grep -i db2
DB2INSTANCE=db2inst1
IBM_DB_LIB=/home/db2inst1/sqllib/lib
IBM_DB_DIR=/home/db2inst1/sqllib
OLDPWD=/home/db2inst1/sqllib/cfg
LD_LIBRARY_PATH=/home/db2inst1/sqllib/lib64:/home/db2inst1/sqllib/lib32
PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/bin:/usr/b
in:/bin:/root/bin:/home/db2inst1/sqllib/bin:/home/db2inst1/sqllib/adm:/home/db2i
nst1/sqllib/misc
PWD=/home/db2inst1/sqllib
DB2_HOME=/home/db2inst1/sqllib
IBM_DB_INCLUDE=/home/db2inst1/sqllib/include
CLASSPATH=/home/db2inst1/sqllib/java/db2java.zip:/home/db2inst1/sqllib/java/sqlj
.zip:/home/db2inst1/sqllib/function:/home/db2inst1/sqllib/java/db2jcc_license_cu
.jar:/home/db2inst1/sqllib/tools/clpplus.jar:/home/db2inst1/sqllib/tools/jline-0
.9.93.jar:/home/db2inst1/sqllib/java/db2jcc.jar:.
DB2LIB=/home/db2inst1/sqllib/lib

[root@system1 sqllib]# quit


bash: quit: command not found
[root@system1 sqllib]# ./db2profile
[root@system1 sqllib]# . ./db2profile
[root@system1 sqllib]# pwd
/home/db2inst1/sqllib
[root@system1 sqllib]# db2
(c) Copyright IBM Corporation 1993,2007
Command Line Processor for DB2 Client 10.5.2

[root@system1 Desktop]# cd /export


bash: cd: /export: No such file or directory
[root@system1 Desktop]# cd /
[root@system1 /]# ls
PMR Nu
[root@system1 db2inst1]# cd *
[root@system1 sqllib]# pwd
/home/db2inst1/sqllib
[root@system1 sqllib]#
[root@system1 sqllib]# ls
adm
ctrlhamirror
gskit
map
python64
sqldbdir
adsm
dasfcn
hmonCache misc
rdf
tmp
backup
db2cshrc
include
msg
Readme
tools
bin
db2dump
infopop
nodes
ruby32
uif
bnd
db2nodes.cfg
java
nodes.reg
ruby64
usercshrc
cfg
db2profile
json
pd
samples
userprofile
cfgcache db2systm
lib
php32
security
conv
doc
lib32
php64
security32
ctrl
fm.system1.reg lib64
profile.env security64
ctrlha
function
log
python32
spmlog
[root@system1 sqllib]# cd bin
[root@system1 bin]# ls
asnacmd
db2cos_preupgrade
db2nkill
asnadmt
db2cos_threshold
db2nps
asnadmtora
db2cos_trap
db2palog
asnanalyze
db2dasstm
db2PArcmd
asnapply
db2dclgn
db2pdraw
asncap
db2demigdbd
db2profc
asnccmd
db2desktop
db2profp
asnclp
db2diag
db2_ps
ASNDONE
db2disable_soap_udf db2rbind
ASNLOAD
db2drdat
db2rc
asnmail
db2dsdcfgfill
db2rcmd
asnmcmd
db2egcf
db2recri
asnmig4c
db2empfa
db2refs.ndx
asnmig8
db2enable_soap_udf db2relocatedb
asnmigpw
db2evmon
db2rmicons
asnmon
db2evtbl
db2rrest
asnoqacmd
db2exfmt
db2rspgn
asnoqapp
db2exmig
db2sampl
asnoqcap
db2expln
db2scont
asnoqccmd
db2fedgentf
db2se
asnpwd
db2flsn
db2setres
asnqacmd
db2fm
db2sqljbind
asnqanalyze
db2fmcd
db2sqljcustomize
asnqapp
db2fmcu
db2sqljprint
asnqcap
db2fmd
db2support
asnqccmd
db2fodc
db2support_internal

asnqmfmt
asntdiff
asntrc
asntrcbp
asntrep
clpplus
db2
You can
prompt.
db2
db2

db2fopt
db2fs
db2ftok
db2fupdt
db2gcf
db2gdeps
db2genseed

db2symlookup
db2tapemgr
db2tbst
db2tdbmgr
db2top
db2uext2.pe
db2uext2.v2

issue database manager commands and SQL statements from the command
For example:
=> connect to sample
=> bind sample.bnd

For general help, type: ?.


For command help, type: ? command, where command can be
the first few keywords of a database manager command. For example:
? CATALOG DATABASE for help on the CATALOG DATABASE command
? CATALOG
for help on all of the CATALOG commands.
To exit db2 interactive mode, type QUIT at the command prompt. Outside
interactive mode, all commands must be prefixed with 'db2'.
To list the current command option settings, type LIST COMMAND OPTIONS.
For more detailed help, refer to the Online Reference Manual.

You might also like