DB2数据库创建非实例用户连接使用数据库

来源:互联网 发布:淘宝皇冠要多久 编辑:程序博客网 时间:2024/06/05 06:36

DB2中数据库用户即为操作系统层面用户:
例如创建test1用户连接使用test9数据库(由db2inst9用户创建):
[root@th1 instance]# useradd test1
[root@th1 instance]# id test1
uid=1008(test1) gid=1008(test1) groups=1008(test1)
[root@th1 instance]# usermod -g db2grp1 test1
[root@th1 instance]# id test1
uid=1008(test1) gid=102(db2grp1) groups=102(db2grp1)

[root@th1 instance]# su - db2inst9
[db2inst9@th1 ~]$ db2 grant dbadm on database to user test1
DB21034E  The command was processed as an SQL statement because it was not a 
valid Command Line Processor command.  During SQL processing it returned:
SQL1024N  A database connection does not exist.  SQLSTATE=08003

[db2inst9@th1 ~]$ db2 list db directory

 System Database Directory

 Number of entries in the directory = 1

Database 1 entry:

 Database alias                       = TEST9
 Database name                        = TEST9
 Local database directory             = /home/db2inst9
 Database release level               = 10.00
 Comment                              =
 Directory entry type                 = Indirect
 Catalog database partition number    = 0
 Alternate server hostname            =
 Alternate server port number         =

[db2inst9@th1 ~]$ db2 connect to test9

   Database Connection Information

 Database server        = DB2/LINUXX8664 10.5.5
 SQL authorization ID   = DB2INST9
 Local database alias   = TEST9

[db2inst9@th1 ~]$ db2 grant dbadm on database to user test1
DB20000I  The SQL command completed successfully.

[db2inst9@th1 ~]$ db2 grant connect on database to user test1
DB20000I  The SQL command completed successfully.

[db2inst9@th1 ~]$ db2 connect to test9 user test1 using test1

   Database Connection Information

 Database server        = DB2/LINUXX8664 10.5.5
 SQL authorization ID   = TEST1
 Local database alias   = TEST9
 
 [db2inst1@th2 ~]$ db2 get db cfg for test9 |grep code
 Database code page                                      = 1208
 Database code set                                       = UTF-8
 Database country/region code                            = 1

db2 =>  create table t1 (c1 int,c2 varchar(30))
DB20000I  The SQL command completed successfully.
db2 =>  insert into t1 values (1,'aa')
DB20000I  The SQL command completed successfully.
db2 => insert into t1 values (2,'bb')
DB20000I  The SQL command completed successfully.
db2 => commit
DB20000I  The SQL command completed successfully.
db2 => select * from t1

C1          C2                            
----------- ------------------------------
          1 aa                            
          2 bb                            

  2 record(s) selected.


0 0
原创粉丝点击