#【例12.1】创建用户lee,口令为'1234'; 创建用户zhang,口令为'5678';创建用户sun,口令为'test'。
select host,user,authentication_string from mysql.user;
create user 'lee'@'localhost' identified by '1234';
create user 'zhang'@'localhost' identified by '5678';
create user 'sun'@'localhost' identified by 'test';
create user 'lihaoqing'@'localhost' identified by '1008';
#【例12.2】 删除用户zhang。
drop user 'zhang'@'localhost';
#【例12.3】 将用户sun的名字修改为qian。
rename user 'sun'@'localhost'
to 'qian'@'localhost';
#【例12.4】 将用户qian的口令修改为'abc'。
set password for 'qian'@'localhost'='abc';
#【例12.5】 授予用户lee在数据库stusys的student表上对学号列和姓名列的SELECT权限。
use stusys;
select * from student;
grant select(sno,sname)
on stusys.student
to 'lihaoqing'@'localhost';
#【例12.6】先创建新用户hong和liu,然后授予它们在数据库stusys的student表上的SELECT和INSERT权限。
create user 'hong'@'localhost','liu'@'localhost';
use stusys;
select * from student;
grant select,insert
on stusys.student
to 'hong'@'localhost','liu'@'localhost'
with grant option;
select host ,db,user,table_name,table_priv
from mysql.tables_priv;
#【例12.7】授予用户qian对数据库stusys执行所有数据库操作的权限。
#【例12.8】授予已存在用户liang对所有数据库中所有表的CREATE和DROP的权限。
#【例12.9】授予已存在用户zhou对所有数据库中所有表的SELECT和UPDATE的权限。
#【例12.10】授予已存在用户ben创建新用户的权限。
#【例12.11】查询以上用户对所有数据库的权限。
#【例12.12】授予已存在用户qiao在数据库stusys的student表上的SELECT和UPDATE权限,并允许将自身的权限授予其他用户。
#【例12.13】收回用户qiao在数据库stusys的student表上的UPDATE权限,
revoke insert
on stusys.student
from 'liu'@'localhost';
select host,db,user, table_name,table_priv
from mysql.tables_priv;
#【例12.14】查询以上用户对student表的权限。