第31課 權(quán)限管理

什么是權(quán)限管理

不同的身份, 可以干不同的事情

新增加的用戶, 權(quán)限很少

我們先新建用戶dog

CREATE USER 'dog'@'localhost' IDENTIFIED BY '123456';
image.png
image.png
image.png
image.png

直接實(shí)例

1. 對新建用戶dog在library.reader表上授予select和delete權(quán)限

沒有權(quán)限時, 直接查詢會報(bào)錯

> 1142 - SELECT command denied to user 'dog'@'localhost' for table 'reader'
> 時間: 0s

賦予權(quán)限

use library;
grant select,DELETE on reader to dog@localhost;
image.png

但是insert操作依然報(bào)錯, 因?yàn)闆]有權(quán)限

INSERT INTO `library`.`reader` 
    ( `readerid`, `readername`, `readerpass`, `retypeid`, `readerdate`, `readerstatus` )
VALUES
    ( '0017', '蘇小東', '123456', 1, '1999-09-09 00:00:00', '有效' );
> 1142 - INSERT command denied to user 'dog'@'localhost' for table 'reader'
> 時間: 0s

2. 授予dog在library.reader上的姓名和密碼的update權(quán)限

grant update(readername,readerpass) on library.reader to dog@localhost;
image.png

3. 授予dog用戶在library數(shù)據(jù)庫中的所有表的select權(quán)限

grant select on library.* to dog@localhost;
image.png

4. 授予dog在library數(shù)據(jù)庫中所有的表操作權(quán)限

grant all on library.* to dog@localhost;
image.png

5. 授予dog對所有數(shù)據(jù)庫所有表的操作權(quán)限

image.png
grant insert, delete, update, select on *.* to dog@localhost;
image.png

6. 授予dog創(chuàng)建新用戶的權(quán)利

mysql> CREATE USER 'cat'@'localhost' IDENTIFIED BY '123456';
1227 - Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation
mysql> 

一開始, dog用戶是沒有創(chuàng)建用戶的權(quán)限的

grant create user on *.* to dog@localhost;

之后, 可以成功

mysql> CREATE USER 'cat'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> 
image.png

7. 回收用戶dog在library.reader表上的select權(quán)限

revoke select on library.reader from dog@localhost;

我不喜歡被人收回權(quán)限, 所以就不演示了...

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • MYSQL 基礎(chǔ)知識 1 MySQL數(shù)據(jù)庫概要 2 簡單MySQL環(huán)境 3 數(shù)據(jù)的存儲和獲取 4 MySQL基本操...
    Kingtester閱讀 8,060評論 5 115
  • ORA-00001: 違反唯一約束條件 (.) 錯誤說明:當(dāng)在唯一索引所對應(yīng)的列上鍵入重復(fù)值時,會觸發(fā)此異常。 O...
    我想起個好名字閱讀 5,972評論 0 9
  • 1,MySQL權(quán)限體系 mysql 的權(quán)限體系大致分為5個層級: 全局層級: 全局權(quán)限適用于一個給定服務(wù)器中的所有...
    不排版閱讀 1,009評論 0 4
  • ORACLE自學(xué)教程 --create tabletestone ( id number, --序號usernam...
    落葉寂聊閱讀 1,243評論 0 0
  • 我們小的時候,父母是這樣的,父母老的時候,我們能否也能這樣…… 我們小的時候,父母是這樣的,父母老的時候,我們能否...
    1980年代末閱讀 185評論 0 0

友情鏈接更多精彩內(nèi)容