>  기사  >  php教程  >  DB2用户表批量授权

DB2用户表批量授权

WBOY
WBOY원래의
2016-06-13 08:51:411159검색

DB2用户表批量授权


一、新建用户
[root@localhost ~]# passwd ghan
Changing password for user ghan.
New UNIX password:
BAD PASSWORD: it is too short
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# su - db2inst2
[db2inst2@localhost ~]$ db2 connect to ghan user ghan
输入 ghan 的当前密码:


数据库连接信息


数据库服务器 = DB2/LINUXX8664 9.7.5
SQL 授权标识 = GHAN
本地数据库别名 = GHAN


二、访问db2int2.t2表报错

[db2inst2@localhost ~]$ db2 "select count(1) from db2inst2.t2"
SQL0551N "GHAN" 不具有对对象 "DB2INST2.T2" 执行操作 "SELECT"
的必需权限或特权。 SQLSTATE=42501



[db2inst2@localhost ~]$ db2 connect to ghan


数据库连接信息


数据库服务器 = DB2/LINUXX8664 9.7.5
SQL 授权标识 = DB2INST2
本地数据库别名 = GHAN

三、生成授权脚本
[db2inst2@localhost ~]$ db2 -x +o -z commands.sql "select 'grant select,insert, update, delete on table ' || trim(tabschema) || '.' || trim(tabname) || ' to user ghan;' from syscat.tables where type = 'T'"
四、修改指写表授权
[db2inst2@localhost ~]$ vi commands.sql

****略***

五、执行授权语句
[db2inst2@localhost ~]$ db2 -tsvf commands.sql
grant select,insert, update, delete on table DB2INST2.EMPL to user ghan
DB20000I SQL 命令成功完成。


grant select,insert, update, delete on table DB2INST2.EMPLDD to user ghan
DB20000I SQL 命令成功完成。


grant select,insert, update, delete on table DB2INST2.STAFF to user ghan
DB20000I SQL 命令成功完成。


grant select,insert, update, delete on table DB2INST2.T1 to user ghan
DB20000I SQL 命令成功完成。



[db2inst2@localhost ~]$ db2 connect to ghan user ghan
输入 ghan 的当前密码:


数据库连接信息


数据库服务器 = DB2/LINUXX8664 9.7.5
SQL 授权标识 = GHAN
本地数据库别名 = GHAN

六、测试授权结果

[db2inst2@localhost ~]$ db2 "select count(*) from db2inst2.t1"


1
-----------
4


1 条记录已选择。
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.