Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2738930
  • 博文数量: 423
  • 博客积分: 7770
  • 博客等级: 少将
  • 技术积分: 4766
  • 用 户 组: 普通用户
  • 注册时间: 2006-11-09 11:58
个人简介

Oracle/DB2/Postgresql/Mysql/Hadoop/Greenplum/Postgres-xl/Mongodb

文章分类

全部博文(423)

文章存档

2019年(3)

2018年(6)

2017年(27)

2016年(23)

2015年(30)

2014年(16)

2013年(31)

2012年(73)

2011年(45)

2010年(14)

2009年(30)

2008年(30)

2007年(63)

2006年(32)

分类: DB2/Informix

2015-11-04 16:38:48


一、新建用户
[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 条记录已选择。
阅读(5657) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~