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

本文档详细介绍了如何在DB2中创建非实例用户,并授权该用户连接到特定数据库。通过创建操作系统用户,将其加入DB2用户组,然后使用DBADM权限在数据库上授予用户权限,确保非实例用户能够成功连接并操作数据库。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值