MySQL 許可權系統詳解

2021-08-28 15:45:17 字數 2046 閱讀 3811

執行grant,revoke或者drop user命令來修改相關許可權,則不需要手工執行flush privileges命令,因為通過

grant,revoke或者drop user命令所做的許可權修改在修改系統表的同時也會更新記憶體結構中的許可權資訊。mysql 5.0.2

還增加了 create user 命令,建立乙個具有初始最低許可權的用記。

1. 授權與**許可權

授權使用:grant 命令,**許可權使用 revoke 命令。還有一種比較暴力的方法是直接修改授權表。授權和**許可權時,

需要指定使用者名稱和主機名,如果不指定主機名,mysql 會認為是 'username'@'%' 的形式。

查詢某個使用者的所擁有的許可權使用:show grants for 'username'@'hostname' 的形式,如:

mysql>show grants for 'root'@'127.0.0.1';

別一種獲得使用者許可權資訊的方法是直接查詢授權表。

2.許可權級別

許可權是向下覆蓋的,範圍越來越少。

(1)global level

稱為全域性許可權控制,作用於整個mysqld,所有許可權資訊儲存在mysql.user 表中,優先順序最高。會覆蓋其他級別的許可權。

授予許可權時,執行grant命令的時候,用「*.*」來指定適用範圍是global level 。

(2) databae level

其作用域是整個資料庫的對像,它能覆蓋比他更下層的table,column和routine這三層的許可權,可以通過兩種方法

來授予:

使用"database.*" 的形式:

mysql>grant drop on test.* to 'root'@'localhost';

先使用 use 選擇資料庫,再使用 * 授權。實際上是當前的整個資料庫。

mysql>use test;

mysql>grant alter on * to root@'localhost';

將授權和**許可權給多個使用者時,使用者之間使用逗號分隔:

mysql>grant alter on test.* to root@'localhost',user@'192.168.1.1';

(3) table level

table level許可權能覆蓋column level和routine level的許可權。作用範圍是資料庫指定的表。例如:

mysql>grant delete,alter on mydb.userinfo to 'root'@'%.unixvip.com';

table level 僅有alter,create,delete,drop,index,insert,select update八種許可權。

(4)column level

columm level 針對列的許可權,column level級別的許可權僅有insert,select和update這三種,它和routine level 的許可權沒有重合部分,和routine level不存要覆蓋問題。columm level 授予許可權和table level 差不多,需要用() 將列括起來:

mysql> grant select(id,value) on test.t1 to 'abc'@'%.unixvip.com';

注意:當某個使用者在向某個表插入(insert)資料的時候,如果該使用者在該表中某列上面沒有insert許可權,

則該列的資料將以預設值填充。

(5) routine level

routine level的許可權主要只有execute和alter routine兩種,主要針對的物件是procedure和function

這兩種物件,在授予routine level許可權的時候,需要指定資料庫和相關物件,如:

mysql>grant execute on test.p1 to 'abc'@'localhost';

還且些其他的特殊選項:

(1)with grant option

在語句加上該欄位,表示可以將許可權再授予其他使用者。

(2)all 關鍵字表示全部許可權,如:

mysql> grant all on test.t1 to 'sailing';

mysql 系統許可權 MySQL 的許可權系統

create user liub localhost identified by liub create table g user id varchar 10 username varchar 20 userpwd varchar 20 insert into g user values 1 liu...

MySQL許可權系統

mysql的許可權系統圍繞著兩個概念 1 認證 確定使用者是否允許連線資料庫伺服器 2 授權 確定使用者是否擁有足夠的許可權執行查詢請求等。與許可權相關的表有user,db,host,tables priv,columns priv。每個表的字段都可分為兩類,一類為作用域字段,一類為許可權字段。作用...

MySQL使用者許可權詳解

如果需要檢視mysql使用者許可權,應該如何實現呢?下面就為您介紹檢視mysql使用者許可權的方法,並對授予mysql使用者許可權的語句進行介紹,供您參考。檢視mysql使用者許可權 show grants for 你的使用者 比如 show grants for root localhost gr...