授權表使用舉例
grant用於給增加使用者和建立許可權,revoke用於刪除使用者許可權。
grant 語法
grant priv_type [(column_list)] [, priv_type [(column_list)]] ...on [object_type]
to user [identified by [password] 'password']
[, user [identified by [password] 'password']] ...
[require
none |
[cipher 'cipher' [and]]
[issuer 'issuer' [and]]
[subject 'subject']]
[with with_option [with_option] ...]
object_type =
table
| function
| procedure
with_option =
grant option
| max_queries_per_hour count
| max_updates_per_hour count
| max_connections_per_hour count
| max_user_connections count
revoke priv_type [(column_list)] [, priv_type [(column_list)]] ...on [object_type]
from user [, user] ...
下面是一些用grant增加使用者和建立許可權的例子:
mysql> grant all privileges on *.* to test@localhost identified by 'test' with grant option;
這句增加乙個本地具有所有許可權的test使用者(超級使用者),密碼是test。on子句中的*.*意味著" 所有資料庫、所有表"。with grant option表示它具有grant許可權。
mysql> grant select,insert,update,delete,create,drop on test.* to test1@'192.168.1.0/255.255.255.0' identified by 'test';
這句是增加了乙個 test1使用者,口令是test,但是它只能從c類子網192.168.1連線,對test庫有 select,insert,update,delete,create,drop操作許可權。
用grant語句建立許可權是不需要再手工重新整理授權表的,因為它已經自動重新整理了。
給使用者建立許可權還可以通過直接修改授權表:
mysql> insert into user values("localhost","test",password("test"),"y","y","y","y","y","y","y","y","y","y","y","y","y","y");
mysql> flush privileges;
這兩句和上面第一句grant的效果是一樣的,也是增加了乙個本地的test超級使用者。我們看到用grant方便多了,而且還不需flush privileges
。 mysql> insert into user (host,user,password) values("192.168.1.0/255.255.255.0","test1",password("test"));
mysql> insert into db values("192.168.1.0/255.255.255.0","test","test1","y","y","y","y","y","y","n","n","n","n")
mysql> flush privileges;
這 三句和上面第二句grant的效果也是一樣的,也是增加了乙個只能從c類子網192.168.1連線,對test庫有 select,insert,update,delete,create,drop操作許可權的test1使用者,口令是test。要取消乙個使用者的許可權,使 用revoke語句。revoke的語法非常類似於grant語句,除了to用from取代並且沒有identified by和with grant
option子句,下面是用revoke刪除使用者許可權的例子:
mysql> revoke all on test.* from test1@'192.168.1.0/255.255.255.0';
這句revoke就撤消了上面第二句 grant建立的許可權,但是test1使用者並沒有被刪除,必須手工從user表刪除:
mysql> delete from user where user='test1';
mysql>
flush privileges;
這樣,test1使用者就徹底刪除了。
這些只是mysql授權表的簡單使用,更多詳細的資料請見mysql提供的手冊。
mysql授權 MySQL使用者授權(GRANT)
當成功建立使用者賬戶後,還不能執行任何操作,需要為該使用者分配適當的訪問許可權。可以使用 show grant for 語句來查詢使用者的許可權。注意 新建立的使用者只有登入 mysql 伺服器的許可權,沒有任何其他許可權,不能進行其他操作。usage on 表示該使用者對任何資料庫和任何表都沒有許...
MySQL使用者許可權管理
網際網路文件整理 mysql的使用者管理,指的是哪個使用者可以連線伺服器,從 連線,連線後能做什麼.mysql中grant語句建立mysql使用者並指定其許可權,而revoke語句刪除許可權。兩條語句實現了mysql資料庫的使用者管理,並提供與直接操作這些表的內容不同的另一種方法。create和re...
mysql 使用者許可權管理
mysql 中顯示所有使用者 select distinct concat user user,host,as query from mysql.user 檢視乙個使用者的許可權 show grants for company 為使用者授權 grant select on b2b search.to...