专门讲讲这个MYSQL授权当中的with grant option的作用
對象的owner將權限賦予某個用戶(如:testuser1)
grant select ,update on bd_corp to testuser1 [with grant option ]
1.如果帶了 with grant option?
那么用戶testuser1可以將select ,update權限傳遞給其他用戶( 如testuser2)
grant select,update on bd_corp to testuser2
2.如果沒帶with grant option
??那么用戶testuser1不能給testuser2授權
簡單的說就是將權限傳遞給第三方
~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~
授權表使用舉例?
grant用于給增加用戶和創建權限,revoke用于刪除用戶權限。?
下面是一些用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?privileges?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用戶就徹底刪除了。?
轉載于:https://www.cnblogs.com/aguncn/p/4313724.html
總結
以上是生活随笔為你收集整理的专门讲讲这个MYSQL授权当中的with grant option的作用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用JDBC进行数据库的事务操作(2)
- 下一篇: HTML5 播放器