MySQL資料隔離grant使用

2021-09-12 06:10:47 字數 1767 閱讀 1760

1.使用者授權

mysql> grant all privileges on *.* to 'user'@'%' identified by 'user123456' with grant option;
1.1許可權分配具體使用

```sql

grant select on *.* to user@localhost; -- user可以查詢 mysql 中所有資料庫中的表。

grant all on *.* to dba@localhost; -- user可以管理 mysql 中的所有資料庫

grant select on testdb.* to dba@localhost; -- user可以查詢 testdb 中的表。

grant select, insert, update, delete on test.data to user@localhost; -- 給與user使用者test資料庫data表的curd許可權

--這裡在給乙個使用者授權多張表時,可以多次執行以上語句。例如下面兩句:

grant select(user_id,username) on test.data to user@'%' identified by '123345';

grant select on test.datainfo to user@'%' identified by '123345';

--grant 作用在表中的列上

grant select(datasetid, datasetscore) on test.datainfo to user@localhost;

```

1.2 許可權可以疊加

​    可以使用grant給使用者新增許可權,許可權會自動疊加,不會覆蓋之前授予的許可權,比如你先給使用者新增乙個select許可權,後來又給使用者新增了乙個insert許可權,那麼該使用者就同時擁有了select和insert許可權。

2.重新整理許可權

mysql> flush privileges;
3.檢視許可權

mysql> show grants for 'user'@'localhost';
​    檢視本地user使用者許可權

4.收回許可權

mysql> revoke create on *.* from 'user@localhost';

mysql> flush privileges;

​    刪除user這個使用者的create許可權,該使用者將不能建立資料庫和表。revoke 使用者許可權後,該使用者只有重新連線 mysql 資料庫,許可權才能生效。

5.mysql許可權設定

5.1許可權表

```tex

mysql資料庫中的3個許可權表:user 、db、 host

許可權表的訪問過程是:

1)先從user表中的host、 user、 password這3個字段中判斷連線的ip、使用者名稱、密碼是否存在表中,存在則通過身份驗證;

2)通過許可權驗證,進行許可權分配時,按照useràdbàtables_privàcolumns_priv的順序進行分配。即先檢查全域性許可權表user,如果user中對應的許可權為y,則此使用者對所有資料庫的許可權都為y,將不再檢查db, tables_priv,columns_priv;如果為n,則到db表中檢查此使用者對應的具體資料庫,並得到db中為y的許可權;如果db中為n,則檢查tables_priv中此資料庫對應的具體表,取得表中的許可權y,以此類推。

```具體每乙個許可權的作用請看

mysql的grant許可權

通過命令 show privileges 可以檢視 grant 許可權 on 資料庫物件 to 使用者 grant select on testdb.to common user grant insert on testdb.to common user grant update on testdb...

my sql 賦許可權 grant

mysql grant 許可權1,許可權2,許可權n on 資料庫名稱.表名稱 to 使用者名稱 使用者位址 identified by 連線口令 許可權1,許可權2,許可權n代表select,insert,update,delete,create,drop,index,alter,grant,re...

MySQL使用者授權(GRANT)

當成功建立使用者賬戶後,還不能執行任何操作,需要為該使用者分配適當的訪問許可權。可以使用 show grant for 語句來查詢使用者的許可權。注意 新建立的使用者只有登入 mysql 伺服器的許可權,沒有任何其他許可權,不能進行其他操作。usage on 表示該使用者對任何資料庫和任何表都沒有許...