# 1.查看user表
use mysql;
desc user;
# 2.查看db表
desc db;
# 3.使用语句CREATE USER创建一个新用户,用户名为zdp,密码为123
-- 创建用户
create user
'zdp'@'localhost'
identified by
'123';
-- 查看用户
select
*
from
mysql.user;
# 4.使用GRANT语句创建一个新用户,用户名为hnzj,密码为123,并授予该用户对“student_s.teacher”表有查询权限
grant
select
on
student_s.teacher
to
'hnzj'@'localhost'
identified by
'123';
# 5.使用INSERT语句在mysql.user表中创建一个新用户,用户名为mythird,密码为123
insert into
mysql.user (host,user,authentication_string,ssl_cipher,x509_issuer,x509_subject)
values
('localhost','mythird',password('123'),'','','');
# 6.删除用户名mythird
drop user 'mythird'@'localhost';
delete from mysql.user where host = 'localhost' and user = 'mythird';
# 7.修改已有用户zdp的用户名称为king
rename user 'zdp'@'localhost' to 'king'@'localhost';
# 8.将root用户的密码修改为abcdef
-- 使用update语句
update
mysql.user
set
authentication_string = 'abcdef'
where
User = 'root' and Host = 'localhost';
-- 使用set语句
set password = password('abcdef');
-- 使用alter语句
alter user
'root'@'localhost'
identified with
myaql_native_password
by
'abcdef';
# 9.使用GRANT语句为用户hnzj授予权限,使该用户对所有数据库有查询、插入权限,该用户也可以将自己的权限授予给其他用户。
grant
select,insert
on
*.*
to
'hnzj'.'localhost'
with grant option;
# 10.使用REVOKE语句收回用户hnzj的查询权限
revoke
select
on
*.*
from
'hnzj'@'localhost';