不一樣的身份, 能夠幹不一樣的事情mysql
新增長的用戶, 權限不多sql
咱們先新建用戶dog數據庫
CREATE USER 'dog'@'localhost' IDENTIFIED BY '123456';
複製代碼
沒有權限時, 直接查詢會報錯安全
> 1142 - SELECT command denied to user 'dog'@'localhost' for table 'reader'
> 時間: 0s
複製代碼
賦予權限post
use library;
grant select,DELETE on reader to dog@localhost;
複製代碼
可是insert操做依然報錯, 由於沒有權限this
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
複製代碼
grant update(readername,readerpass) on library.reader to dog@localhost;
複製代碼
grant select on library.* to dog@localhost;
複製代碼
grant all on library.* to dog@localhost;
複製代碼
grant insert, delete, update, select on *.* to dog@localhost;
複製代碼
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用戶是沒有建立用戶的權限的spa
grant create user on *.* to dog@localhost;
複製代碼
以後, 能夠成功3d
mysql> CREATE USER 'cat'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
mysql>
複製代碼
revoke select on library.reader from dog@localhost;
複製代碼
我不喜歡被人收回權限, 因此就不演示了...code