1、用戶賬號管理
//對密碼進行明文加密設置 ->select password(456); //能夠得到對應的散列值 ->create user 'zhangsan'@'localhost' identified by'123', ->'lisi'@'localhost' identified by password ->'*531E182E272080AB0740FE2F2D689DBE0156E04'; //創建了兩個賬號,一個zhangsan密碼為123,一個lisi,密碼為456 ->drop user zhangshan@localhost; //刪除張三的賬號 ->rename user 'lisi'@'localhost' to 'wangwu
2、grant授予權限
實例:授予用戶zhangsan在數據庫mysql_test的表customers上擁有對列cust_id和列cust_name的select權限 ->grant select(cust_id,cust_name) ->on mysql_test.customers ->to'zhangsan'@'localhost'; 實例:授予當前系統中一個不存在的用戶liming和用戶huang,要求創建這兩個用戶,並設置對應的系統 登錄口令,同時授予他們在數據庫mysql_test的表customers上擁有select和update的權限 ->grant select ,update ->on mysql_test.customers ->to'liming'@'localhost' identified by '123', ->'huang'@'localhost' identified by '789'; 實例:授予系統中已存在的wangwu可以在數據庫mysql_test中執行所有數據庫操作的權限 ->grant all ->on mysql_test.* ->to'wangwu'@'localhost'; 實例:授予系統中已存在wnagwu擁有創建用戶的權限 ->grant create user ->on *.* ->to 'wangwu'@'localhost'; 實例:授予系統中已存在wnagwu擁有創建用戶的權限,授予給其他用戶 ->grant create user ->on *.* ->to 'wangwu'@'localhost' ->with grant option;
3、回收權限REVOKE
實例:從用戶WANG回收對關系S的查詢,修改權限的SQL語句 REVOKE SELECT,UPDATE ON S FROM WANG; //REVOKE用於指定權限的名稱,即查詢,修改權限 //ON用於指定要授予權限的數據名或表名 即S //FROM用於指定被撤銷權限的用戶 即WANG
實例:回收系統中已存在的用戶zhou在數據庫mysql_test的表customers上的SELECT權限
revoke select
on mysql_test.customers
from 'zhou'@'localhost';
實例:在mysql中,授予當前系統中一個不存在的用戶zhou在數據庫中mysql_test的表customers上擁有SELECT和UPDATE的權限,並允許他們將自身的這個權限授予給其他用戶
grant select,update
on mysql_test.customers
to 'zhou'@'localhost' identified by '123' //設置密碼
with grant option; //允許他們將權限授予其他用戶