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; //允许他们将权限授予其他用户