首頁 > php教程 > php手册 > 主體

DB2用户表批量授权

WBOY
發布: 2016-06-13 08:51:41
原創
1125 人瀏覽過

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 条记录已选择。
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門推薦
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!