首页 > 数据库技术 > 详细

DB2简单使用-命令行

时间:2019-11-20 14:45:53      阅读:130      评论:0      收藏:0      [点我收藏+]

.数据库实例的启动
首先要启动数据库的实例,即切换到db2inst1用户(注:db2inst1用户为当前数据库的实例),然后执行db2start启动数据库的实例

[root@node129 db2_expc]#  su - db2inst1
上一次登录:三 11月 20 14:10:01 CST 2019

[db2inst1@node129 ~]$ db
Display all 200 possibilities? (y or n)
db2                     db2egcf                 db2imdbd                db2setres
db2acsutil              db2empfa                db2imdbm                db2star2
db2addicons             db2enable_soap_udf      db2imnod                db2start
db2adutl                db2evmon                db2imsslcfg             db2stop
db2advis                db2evtbl                db2inidb                db2stop2
db2_aram                db2exfmt                db2inspf                db2stst
db2audit                db2exmig                db2instance             db2support
db2audit.ddl            db2expln                db2javit                db2support_internal
db2batch                db2fedgentf             db2jdbcbind             db2symlookup
db2bfd                  db2flsn                 db2jdkp                 db2sysc
db2bp                   db2fm                   db2langdir              db2syscr
db2bpq                  db2fmcd                 db2latchtrace           db2tapemgr
db2cacpy                db2fmcu                 db2ldcfg                db2tbst
db2_call_stack          db2fmd                  db2lddrg                db2tdbmgr
db2cap                  db2fmp                  db2level                db2top
db2cat                  db2fmp32                db2licd                 db2trc
db2cfexp                db2fmpr                 db2licm                 db2uext2.pe
db2cfimp                db2fmpr32               db2_local_ps            db2uext2.v2
db2checkSD              db2fmpterm              db2logsForRfwd          db2untag
db2checkSD_exe          db2fodc                 db2look                 db2updserv
db2chglibpath           db2fopt                 db2ls                   db2updv10
db2chparm               db2fs                   db2lspwd                db2usrinf
db2ckbkp                db2ftok                 db2lueff                db2val
db2cklog                db2fupdt                db2move                 db2vend
db2ckrst                db2gcf                  db2mqCheck              db2xdbmig
db2ckupgrade            db2gdeps                db2mqlsn                db2xdbsg
db2ckupgrade32_exe      db2genp                 db2mtrk                 db_archive
db2ckupgrade64_exe      db2genseed              db2ncstk                db_checkpoint
db2cli                  db2_glm_detach          db2nkill                db_deadlock
db2cluster              db2gov                  db2nps                  db_dump
db2cmnclp               db2govd                 db2palog                db_dump185
db2cos                  db2govlg                db2PArcmd               dbhome
db2cos_clp              db2gpinf                db2path                 db_hotbackup
db2cos_datacorruption   db2gpmap                db2pd                   db_load
db2cos_hang             db2greg                 db2pdcfg                db_log_verify
db2cos_lib              db2haicu                db2pdraw                db_printlog
db2cos_member           db2hareg                db2_ps                  db_recover
db2cos_perf             db2havend               db2rbind                db_replicate
db2cos_preupgrade       db2help                 db2rcmd                 db_stat
db2cos_threshold        db2iauto                db2recri                db_tuner
db2cos_trap             db2icdocs               db2relocatedb           db_upgrade
db2dart                 db2iclean               db2rfpen                dbus-binding-tool
db2dasstm               db2IdentifyType1        db2rmicons              dbus-cleanup-sockets
db2dasstml              db2IdentifyType1_exe    db2rrest                dbus-daemon
db2demigdbd             db2IdentifyType1_v8_32  db2rspgn                dbus-launch
db2desktop              db2IdentifyType1_v8_64  db2rstar                dbus-monitor
db2diag                 db2IdentifyType1_v9_32  db2rstop                dbus-send
db2disable_soap_udf     db2IdentifyType1_v9_64  db2sampl                dbus-uuidgen
db2drdat                db2ilist                db2scont                db_verify
db2dsdcfgfill           db2imaudcfg             db2set                  dbwrap_tool
[db2inst1@node129 ~]$ db

  

显示所有的实例
先启动-显示所有

[db2inst1@node129 ~]$ db2start
SQL1026N  The database manager is already active.
[db2inst1@node129 ~]$ db2list
bash: db2list: 未找到命令...
[db2inst1@node129 ~]$ db2ilist
db2inst1

  显示当前

[db2inst1@node129 ~]$ db2 get instance
 The current database manager instance is:  db2inst1
 

  列出当前实例中有哪些数据库

 
 [db2inst1@node129 ~]$ db2 list db directory

 System Database Directory

 Number of entries in the directory = 1

Database 1 entry:

 Database alias                       = SAMPLE
 Database name                        = SAMPLE
 Local database directory             = /home/db2inst1
 Database release level               = f.00
 Comment                              =
 Directory entry type                 = Indirect
 Catalog database partition number    = 0
 Alternate server hostname            =
 Alternate server port number         =

[db2inst1@node129 ~]$ 

  创建数据库   li_db,连接数据库

[db2inst1@node129 ~]$ db2 create database li_db
DB20000I  The CREATE DATABASE command completed successfully.

[db2inst1@node129 ~]$ db2 connect to li_db

   Database Connection Information

 Database server        = DB2/LINUXX8664 10.1.0
 SQL authorization ID   = DB2INST1
 Local database alias   = LI_DB

  

注:用密码情况下格式[db2inst1@localhost ~]$ db2 connect to test user username using password

db2 connect to <database> user <username> using <password>

查看表空间

[db2inst1@node129 ~]$ db2 list tablespaces

           Tablespaces for Current Database

 Tablespace ID                        = 0
 Name                                 = SYSCATSPACE
 Type                                 = Database managed space
 Contents                             = All permanent data. Regular table space.
 State                                = 0x0000
   Detailed explanation:
     Normal

 Tablespace ID                        = 1
 Name                                 = TEMPSPACE1
 Type                                 = System managed space
 Contents                             = System Temporary data
 State                                = 0x0000
   Detailed explanation:
     Normal

 Tablespace ID                        = 2
 Name                                 = USERSPACE1
 Type                                 = Database managed space
 Contents                             = All permanent data. Large table space.
 State                                = 0x0000
   Detailed explanation:
     Normal

 Tablespace ID                        = 3
 Name                                 = SYSTOOLSPACE
 Type                                 = Database managed space
 Contents                             = All permanent data. Large table space.
 State                                = 0x0000
   Detailed explanation:
     Normal

[db2inst1@node129 ~]$ 

  列出数据库 用户表

[db2inst1@node129 ~]$ db2 list tables

Table/View                      Schema          Type  Creation time             
------------------------------- --------------- ----- --------------------------

  0 record(s) selected.

  注:上面信息说明数据库li_db中还没有表

在数据库li_db中创建表student   插入数据  查询

[db2inst1@node129 ~]$ db2 "create table student (id int,name varchar(30),age int)"
DB20000I  The SQL command completed successfully.
[db2inst1@node129 ~]$ db2 list tables

Table/View                      Schema          Type  Creation time             
------------------------------- --------------- ----- --------------------------
STUDENT                         DB2INST1        T     2019-11-20-14.31.46.996691

  1 record(s) selected.

[db2inst1@node129 ~]$ 
[db2inst1@node129 ~]$ db2 "insert into student values (1,‘Tom‘,22)"
DB20000I  The SQL command completed successfully.
[db2inst1@node129 ~]$ db2 "select * from student"

ID          NAME                           AGE        
----------- ------------------------------ -----------
          1 Tom                                     22

  1 record(s) selected.

  

查看表结构

[db2inst1@node129 ~]$ db2 describe table student

                                Data type                     Column
Column name                     schema    Data type name      Length     Scale Nulls
------------------------------- --------- ------------------- ---------- ----- ------
ID                              SYSIBM    INTEGER                      4     0 Yes   
NAME                            SYSIBM    VARCHAR                     30     0 Yes   
AGE                             SYSIBM    INTEGER                      4     0 Yes   

  3 record(s) selected.

  

 

 

DB2简单使用-命令行

原文:https://www.cnblogs.com/l7planet/p/11897665.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!