mysql學習筆記之許可權
阿新 • • 發佈:2018-10-31
MySQL許可權的定義
01.作用物件
庫、表
02.許可權
細化到具體命令
03.歸屬
每次設定只能有一個“屬主”。沒有屬組或其他 概念
grant all on test.* to [email protected]‘10.0.0.%’ identified by ‘123’;
grant --授權命令 all --所有許可權代表,等價於把所有許可權輸一遍 on --指定作用物件 test,* --作用物件 to --指定使用者 identified by --指定密碼 PS:grant ,若是使用者不存在會自動建立使用者
作用物件分解:
*.*:當前MySQL資料庫中所有庫中的所有表,全域性。(一般為管理員)
test.*:單庫級別,當前test庫下的所有表
test.t1:單表級別,當前test庫下的t1表
企業中許可權的使用(溝通)
1.許可權範圍:指定庫or表
2.使用網段:localhost 或者 其他網段
3.使用者名稱:按需設定
4.密碼:按需設定
PS:root許可權不可隨意給與
討論:對一個使用者在不同級別設定許可權,最終許可權是什麼
測試環境
mysql> create database test;
mysql> use test
mysql> create table t1 (id int);
mysql> create table t2 (id int);
mysql> create database test01;
mysql> use test01
mysql> create table tt1(id int);
a) mysql> grant select on *.* to [email protected]'10.0.0.%' identified by '123';
b) mysql> grant insert,delete,update on test.* to [email protected]'10.0.0.%' identified by '123';
c) mysql> grant all on test.t1 to [email protected]'10.0.0.%' identified by '123';
問:某客戶端程式使用test使用者從10.0.0.210 登陸到mysql中後
1)對t1表的管理能力
同時滿足授權a b c,所以最終許可權為a+b+c
2) 對t2表的管理能力?
同時滿足了授權a b ,所以最終許可權為a+b
3)對tt1表的管理能力
因為只滿足授權(a),所以對tt1表只有select許可權
mysql> drop tables tt1;
ERROR 1142 (42000): DROP command denied
mysql> select * from tt1;
Empty set (0.00 sec)