【DB2】普通使用者最小查詢許可權分配
db2 connect to <db-name>
1. 分配普通使用者連線許可權
db2 "grant connect on database to user db-user"
2. 分配使用者
SQL5193N
db2 "grant usage on workload SYSDEFAULTUSERWORKLOAD to user db2read"
db2 list db directory | grep -i "Database alias" | awk '{print "db2 connect to " $4}'
3. 圖形化工具可能報錯
db2 "grant execute on package nullid.syssh200 to user db-user"
先測試
db2 list db directory | grep -i "Database alias" | awk '{print "db2 connect to " $4 "; db2 -x \"select '\''grant select on table '\'' || trim(tabschema) || '\''.''\'' || trim(tabname) || '\'' to user db2read;'\'' from syscat.tables\" > grant_db.sql"}'
然後生成執行語句
db2 list db directory | grep -i "Database alias" | awk '{print "db2 connect to " $4 "; db2 -x \"select '\''grant select on table '\'' || trim(tabschema) || '\''.''\'' || trim(tabname) || '\'' to user db2read;'\'' from syscat.tables\" > grant_db.sql; db2 -tvf grant_db.sql"}'