--當(dāng)前庫(kù)下面的表
select
u.name,
o.name,
(select convert(varchar(8000), value) from ::fn_listextendedproperty(NULL, 'user', u.name, 'table', o.name, null, null) where name = 'MS_Description') as coln
from
sys.sysobjects o
join sys.schemas u on (u.schema_id = o.uid)
where
o.type in ('U')
order by 1, 2
--當(dāng)前庫(kù)下面的用戶
select * from sysusers
where gid = 0
and hasdbaccess = 1
and islogin = 1
and issqluser = 1
--當(dāng)前庫(kù)下面的用戶
EXEC sp_helprotect @username ='用戶名'
--語(yǔ)法格式
sp_helprotect [ [ @name = ] 'object_statement' ]
[ , [ @username = ] 'security_account' ]
[ , [ @grantorname = ] 'grantor' ]
[ , [ @permissionarea = ] 'type' ]
密碼不可見(jiàn)。
查看用戶權(quán)限
show grants for 你的用戶
比如:
show grants for root@'localhost';
mysql> use mysql;
Database changed
mysql> select user,host from user;
+———+———————–+
| user | host |
+———+———————–+
| root | 127.0.0.1 |
| | localhost |
| root | localhost |
| | localhost.localdomain |
| root | localhost.localdomain |
+———+———————–+
7 rows in set (0.00 sec)
mysql> show grants for root@'localhost';
+———————————————————————+
| Grants for root@localhost |
+———————————————————————+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION |
+———————————————————————+
1 row in set (0.00 sec)
mysql>
mysql> select db,user ,host from db;
+———+——+————–+
| db | user | host |
+———+——+————–+
| test | | % |
| test\_% | | % |
| db | test | 172.20.1.124 |
+———+——+————–+
3 rows in set (0.00 sec)
mysql>
Grant 用法
mysql> GRANT ON
-> TO [IDENTIFIED BY ""]
-> [WITH GRANT OPTION];
例如:GRANT USAGE ON *.* TO 'discuz'@'localhost' IDENTIFIED BY PASSWORD '123456′;
參數(shù)說(shuō)明:
是一個(gè)用逗號(hào)分隔的你想要賦予的權(quán)限的列表。你可以指定的權(quán)限可以分為三種類(lèi)型:
數(shù)據(jù)庫(kù)/數(shù)據(jù)表/數(shù)據(jù)列權(quán)限:
Alter: 修改已存在的數(shù)據(jù)表(例如增加/刪除列)和索引。
Create: 建立新的數(shù)據(jù)庫(kù)或數(shù)據(jù)表。
Delete: 刪除表的記錄。
Drop: 刪除數(shù)據(jù)表或數(shù)據(jù)庫(kù)。
INDEX: 建立或刪除索引。
Insert: 增加表的記錄。
Select: 顯示/搜索表的記錄。
Update: 修改表中已存在的記錄。
全局管理權(quán)限:
file: 在MySQL服務(wù)器上讀寫(xiě)文件。
PROCESS: 顯示或殺死屬于其它用戶的服務(wù)線程。
RELOAD: 重載訪問(wèn)控制表,刷新日志等。
SHUTDOWN: 關(guān)閉MySQL服務(wù)。
特別的權(quán)限:
ALL: 允許做任何事(和root一樣)。
USAGE: 只允許登錄–其它什么也不允許做。
只要將用戶1下所有表的查詢權(quán)限賦給用戶2即可。但是,用戶1下可能有很多表,如果一條一條地寫(xiě)grant語(yǔ)句很不現(xiàn)實(shí),這里介紹一種便捷的方法:通過(guò)查詢語(yǔ)句得到grant賦權(quán)限腳本,執(zhí)行一下就可以了。
SQL> show user
USER 為"SYS"
SQL> create user tt
2 identified by tt;
用戶已創(chuàng)建
SQL> grant create session to tt;
授權(quán)成功。
SQL> select 'grant select on '||owner||'.'||object_name|| ' to user1;'
2 from dba_objects
3 where object_type='TABLE' and wner='SCOTT';
'GRANTSELECTON'||OWNER||'.'||OBJECT_NAME||'TOUSER1;'
------------------------------------------------------------------------------
grant select on SCOTT.BONUS to user1;
grant select on SCOTT.CC to user1;
grant select on SCOTT.CC1 to user1;
grant select on SCOTT.DEPT to user1;
grant select on SCOTT.EMP to user1;
grant select on SCOTT.SALGRADE to user1;
grant select on SCOTT.T1 to user1;
grant select on SCOTT.T2 to user1;
grant select on SCOTT.TT to user1;
已選擇9行。
復(fù)制上面的查詢結(jié)果執(zhí)行一下就可以了。如果查詢結(jié)果太多的話,可以將這樣做:
set pages 999;
set heading off;
spool run_grant.sql
select 'grant select on '||owner||'.'||object_name|| ' to user1;'
from dba_objects
where object_type='TABLE' and wner='SCOTT';
spool off;
@run_grant
這是一種很方便高效的方法,可以使工作事半功倍。
把所有表的查詢權(quán)限賦給另一個(gè)用戶
grant select any table to QUERY;
查看當(dāng)前用戶的缺省表空間 SQL>select username,default_tablespace from user_users; 查看當(dāng)前用戶的角色 SQL>select * from user_role_privs; 查看當(dāng)前用戶的系統(tǒng)權(quán)限和表級(jí)權(quán)限 SQL>select * from user_sys_privs; SQL>select * from user_tab_privs; 查看用戶下所有的表 SQL>select * from user_tables; 顯示用戶信息(所屬表空間) select default_tablespace,temporary_tablespace from dba_users where username='GAME'; 1、用戶 查看當(dāng)前用戶的缺省表空間 SQL>select username,default_tablespace from user_users; 查看當(dāng)前用戶的角色 SQL>select * from user_role_privs; 查看當(dāng)前用戶的系統(tǒng)權(quán)限和表級(jí)權(quán)限 SQL>select * from user_sys_privs; SQL>select * from user_tab_privs; 顯示當(dāng)前會(huì)話所具有的權(quán)限 SQL>select * from session_privs; 顯示指定用戶所具有的系統(tǒng)權(quán)限 SQL>select * from dba_sys_privs where grantee='GAME'; 顯示特權(quán)用戶 select * from v$pwfile_users; 顯示用戶信息(所屬表空間) select default_tablespace,temporary_tablespace from dba_users where username='GAME'; 顯示用戶的PROFILE select profile from dba_users where username='GAME';2、表 查看用戶下所有的表 SQL>select * from user_tables; 查看名稱包含log字符的表 SQL>select object_name,object_id from user_objects where instr(object_name,'LOG')>0; 查看某表的創(chuàng)建時(shí)間 SQL>select object_name,created from user_objects where object_name=upper('&table_name'); 查看某表的大小 SQL>select sum(bytes)/(1024*1024) as "size(M)" from user_segments where segment_name=upper('&table_name'); 查看放在ORACLE的內(nèi)存區(qū)里的表 SQL>select table_name,cache from user_tables where instr(cache,'Y')>0; 3、索引 查看索引個(gè)數(shù)和類(lèi)別 SQL>select index_name,index_type,table_name from user_indexes order by table_name; 查看索引被索引的字段 SQL>select * from user_ind_columns where index_name=upper('&index_name'); 查看索引的大小 SQL>select sum(bytes)/(1024*1024) as "size(M)" from user_segments where segment_name=upper('&index_name'); 4、序列號(hào) 查看序列號(hào),last_number是當(dāng)前值 SQL>select * from user_sequences; 5、視圖 查看視圖的名稱 SQL>select view_name from user_views; 查看創(chuàng)建視圖的select語(yǔ)句 SQL>set view_name,text_length from user_views; SQL>set long 2000; 說(shuō)明:可以根據(jù)視圖的text_length值設(shè)定set long 的大小 SQL>select text from user_views where view_name=upper('&view_name'); 6、同義詞 查看同義詞的名稱 SQL>select * from user_synonyms; 7、約束條件 查看某表的約束條件 SQL>select constraint_name, constraint_type,search_condition, r_constraint_name from user_constraints where table_name = upper('&table_name'); SQL>select c.constraint_name,c.constraint_type,cc.column_name from user_constraints c,user_cons_columns cc where c.owner = upper('&table_owner') and c.table_name = upper('&table_name') and c.owner = cc.owner and c.constraint_name = cc.constraint_name order by cc.position; 8、存儲(chǔ)函數(shù)和過(guò)程 查看函數(shù)和過(guò)程的狀態(tài) SQL>select object_name,status from user_objects where object_type='FUNCTION'; SQL>select object_name,status from user_objects where object_type='PROCEDURE'; 查看函數(shù)和過(guò)程的源代碼 SQL>select text from all_source where owner=user and name=upper('&plsql_name');。
1.System/Sysdba用戶,可以使用以下SQL查看:
select * from dba_dependencies where referenced_name =upper('emp') and owner=upper('tmd')
2.普通用戶可以使用以下SQL查看:
select * from all_dependencies where referenced_name =upper('emp')
聲明:本網(wǎng)站尊重并保護(hù)知識(shí)產(chǎn)權(quán),根據(jù)《信息網(wǎng)絡(luò)傳播權(quán)保護(hù)條例》,如果我們轉(zhuǎn)載的作品侵犯了您的權(quán)利,請(qǐng)?jiān)谝粋€(gè)月內(nèi)通知我們,我們會(huì)及時(shí)刪除。
蜀ICP備2020033479號(hào)-4 Copyright ? 2016 學(xué)習(xí)鳥(niǎo). 頁(yè)面生成時(shí)間:3.023秒