informix - 更改数据库 Informix 上的用户权限
问题描述
在 Informix 中,如何更改数据库、从咨询到选择、删除、更新、插入的所有表的用户权限。
我试着用这样的东西
dbaccess DATABASE exec for i in (select table_name from user_tables) loop execute immediate 'grant select,insert,update,delete on '||i.table_name||' to USER'; end loop
但它没有用。
解决方案
DB-Access 不是我最喜欢的工具,但它可以在 shell 脚本的一些支持下完成这项工作。您最终会调用它两次,一次是生成表名列表,一次是处理权限。
鉴于文件so-6952-3871.sql
包含:
unload to '/dev/stdout'
select tabname
from "informix".systables
where tabid >= 100
and tabtype = 'T';
shell 脚本so-6952-3871.sh
完成这项工作,撤销现有权限并授予新权限:
#!/bin/sh
#
# @(#)$Id$
#
# Grant select, insert, delete, update permission on all user tables in a database to a named user.
: "${DBACCESS:=dbaccess}"
if [ $# = 0 ]
then
echo "$0: you must specify the database and at least one user" >&2
echo "Usage: $0 database user [...]" >&2
fi
dbase="$1"
shift
if [ $# = 0 ]
then
echo "$0: must specify at least one user" >&2
echo "Usage: $0 database user [...]" >&2
exit 1
fi
$DBACCESS $dbase so-6952-3871.sql |
sed -n '/^\([a-zA-Z0-9_]*\)|$/ s//\1/p' |
while read tabname
do
#echo "Table: $tabname" >&2
for user in "$@"
do
echo "revoke all on $tabname from $user;"
echo "grant select, insert, delete, update on $tabname to $user;"
done
done |
$DBACCESS $dbase -
我选择使用"informix".systables
系统目录表,因为我的数据库中没有调用表user_tables
。您可以根据需要细化选择标准(例如,省略时间序列表)。
如果您有足够的权限来授予和撤销数据库中的权限(例如,作为 DBA 或作为用户informix
),这应该可以正常工作。
我没有使用 DB-Access,而是使用我的 SQLCMD(可从IIUG Software Archive获得),我编写它是为了在 shell 脚本上下文中表现一致,而 DB-Access 则不然。它可以追溯到 1986 年(之前有dbaccess
; 在那些日子里,你使用的是 - DB-Access 是在一个晚上isql
被雕刻出来的)。isql
它与 Microsoft 的同名 johnny-come-lately 程序没有任何关系——除了名称和具有相同的通用目的(操作 SQL 数据库)。使用 SQLCMD,线路无需sed
在标准输出上忽略来自 DB-Access 的噪声输出。
推荐阅读
- php - 我如何在附加字符串的数组中提取数组
- c++ - 使用 cpp-httplib 上传文件
- javascript - 如何在 contenteditable 元素上禁用备忘录?
- python - 通过本地系统连接到 google colab
- flutter - 在flutter中设置输入并获取输出到自定义tensorflow lite
- r - R:组合向量以形成一个数据框,第一列是向量名称
- autodesk-forge - SVF2 Public Beta - 模型未转换为 SVF2
- c++ - 如何将 c 字符串引用传递给类函数模板?
- javascript - 如何使用javascript获取元素的链接?
- pandas - 每年对具有远期值的每日数据重新采样