まず、インストール中に作成したDB2インスタンス"db2inst1"のインスタンスオーナーユーザーである"db2inst1"ユーザーでfedora11/s390xにログインします。パスワードはDB2のインストール中に設定したものを使用します。
[hercules@ap01 ~]$ ssh -l db2inst1 192.168.200.3 db2inst1@192.168.200.3's password:
"db2start"コマンドでdb2inst1インスタンスを起動します。"SQL1063N DB2START processing was successful" メッセージが表示されれば、インスタンスの起動に成功しています。
db2inst1@localhost ~]$ db2start 03/19/2010 11:42:36 0 0 SQL1063N DB2START processing was successful. SQL1063N DB2START processing was successful.
DB2にはサンプルデータベース作成用のコマンド"db2sampl"が付属しています("db2sample"ではないので注意)ので、これを実行します。"'db2sampl' processing complete."のメッセージが表示されれば完了です。
[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.
作成した"SAMPLE"データベースに接続してみます。 "db2 connect to sample"を実行します。Database server名が"DB2/LINUXZ64"になっていますね。
[db2inst1@localhost ~]$ db2 connect to sample Database Connection Information Database server = DB2/LINUXZ64 9.7.1 SQL authorization ID = DB2INST1 Local database alias = SAMPLE
"SAMPLE"データベース内のテーブル一覧を表示してみます。 "db2 list tables"を実行します。
[db2inst1@localhost ~]$ db2 list tables Table/View Schema Type Creation time ------------------------------- --------------- ----- -------------------------- ACT DB2INST1 T 2010-03-19-11.53.14.863451 ADEFUSR DB2INST1 S 2010-03-19-11.53.51.886267 CATALOG DB2INST1 T 2010-03-19-11.54.38.632393 CL_SCHED DB2INST1 T 2010-03-19-11.53.12.168361 CUSTOMER DB2INST1 T 2010-03-19-11.54.37.661858 DEPARTMENT DB2INST1 T 2010-03-19-11.53.12.344265 DEPT DB2INST1 A 2010-03-19-11.53.12.769500 EMP DB2INST1 A 2010-03-19-11.53.13.125422 EMPACT DB2INST1 A 2010-03-19-11.53.14.835833 EMPLOYEE DB2INST1 T 2010-03-19-11.53.12.784090 EMPMDC DB2INST1 T 2010-03-19-11.54.12.189308 EMPPROJACT DB2INST1 T 2010-03-19-11.53.14.673046 EMP_ACT DB2INST1 A 2010-03-19-11.53.14.851410 EMP_PHOTO DB2INST1 T 2010-03-19-11.53.13.139212 EMP_RESUME DB2INST1 T 2010-03-19-11.53.13.589414 INVENTORY DB2INST1 T 2010-03-19-11.54.37.422684 IN_TRAY DB2INST1 T 2010-03-19-11.53.15.151188 ORG DB2INST1 T 2010-03-19-11.53.15.263343 PRODUCT DB2INST1 T 2010-03-19-11.54.36.979472 PRODUCTSUPPLIER DB2INST1 T 2010-03-19-11.54.39.421663 PROJ DB2INST1 A 2010-03-19-11.53.14.385700 PROJACT DB2INST1 T 2010-03-19-11.53.14.398559 PROJECT DB2INST1 T 2010-03-19-11.53.14.011351 PURCHASEORDER DB2INST1 T 2010-03-19-11.54.38.075299 SALES DB2INST1 T 2010-03-19-11.53.15.464041 STAFF DB2INST1 T 2010-03-19-11.53.15.359394 STAFFG DB2INST1 T 2010-03-19-11.53.48.101443 SUPPLIERS DB2INST1 T 2010-03-19-11.54.39.021910 VACT DB2INST1 V 2010-03-19-11.53.15.712022 VASTRDE1 DB2INST1 V 2010-03-19-11.53.15.904366 VASTRDE2 DB2INST1 V 2010-03-19-11.53.15.955794 VDEPMG1 DB2INST1 V 2010-03-19-11.53.15.806789 VDEPT DB2INST1 V 2010-03-19-11.53.15.560107 VEMP DB2INST1 V 2010-03-19-11.53.15.640160 VEMPDPT1 DB2INST1 V 2010-03-19-11.53.15.851954 VEMPLP DB2INST1 V 2010-03-19-11.53.16.344550 VEMPPROJACT DB2INST1 V 2010-03-19-11.53.15.773254 VFORPLA DB2INST1 V 2010-03-19-11.53.16.159036 VHDEPT DB2INST1 V 2010-03-19-11.53.15.607765 VPHONE DB2INST1 V 2010-03-19-11.53.16.301730 VPROJ DB2INST1 V 2010-03-19-11.53.15.674485 VPROJACT DB2INST1 V 2010-03-19-11.53.15.739944 VPROJRE1 DB2INST1 V 2010-03-19-11.53.16.009754 VPSTRDE1 DB2INST1 V 2010-03-19-11.53.16.058355 VPSTRDE2 DB2INST1 V 2010-03-19-11.53.16.108992 VSTAFAC1 DB2INST1 V 2010-03-19-11.53.16.201096 VSTAFAC2 DB2INST1 V 2010-03-19-11.53.16.248972 47 record(s) selected.
テーブルの定義を表示させる場合は"db2 describe table <テーブル名>"コマンドを使います。 "STAFF"テーブルに対してこのコマンドを実行してみます。
[db2inst1@localhost ~]$ db2 describe table staff
Data type Column
Column name schema Data type name Length Scale Nulls
------------------------------- --------- ------------------- ---------- ----- ------
ID SYSIBM SMALLINT 2 0 No
NAME SYSIBM VARCHAR 9 0 Yes
DEPT SYSIBM SMALLINT 2 0 Yes
JOB SYSIBM CHARACTER 5 0 Yes
YEARS SYSIBM SMALLINT 2 0 Yes
SALARY SYSIBM DECIMAL 7 2 Yes
COMM SYSIBM DECIMAL 7 2 Yes
7 record(s) selected.
STAFFテーブルに対してSQLを発行してみます。
[db2inst1@localhost ~]$ db2 "select id,name,dept from staff"
ID NAME DEPT
------ --------- ------
10 Sanders 20
20 Pernal 20
30 Marenghi 38
40 O'Brien 38
50 Hanes 15
60 Quigley 38
70 Rothman 15
80 James 20
90 Koonitz 42
100 Plotz 42
110 Ngan 15
120 Naughton 38
130 Yamaguchi 42
140 Fraye 51
150 Williams 51
160 Molinare 10
170 Kermisch 15
180 Abrahams 38
190 Sneider 20
200 Scoutten 42
210 Lu 10
220 Smith 51
230 Lundquist 51
240 Daniels 10
250 Wheeler 51
260 Jones 10
270 Lea 66
280 Wilson 66
290 Quill 84
300 Davis 84
310 Graham 66
320 Gonzales 66
330 Burke 66
340 Edwards 84
350 Gafney 84
35 record(s) selected.
"db2 terminate"コマンドで、接続を解除できます(db2inst1インスタンスは停止しません)。
[db2inst1@localhost ~]$ db2 terminate DB20000I The TERMINATE command completed successfully.
"db2stop"コマンドを実行すると、"db2inst1"インスタンスが停止します。
[db2inst1@localhost ~]$ db2stop 2010-03-19 12:01:07 0 0 SQL1064N DB2STOP processing was successful. SQL1064N DB2STOP processing was successful.
非常に簡単ですが、DB2インストール後の動作確認を行ってみました。
0 件のコメント:
コメントを投稿