mysql用root账户建立用户和赋予权限

时间:2022-09-01 08:54:08

1.创建用户

create user guest_test@localhost identified by "root";
-- 创建名为guest_test的用户

2.赋予权限

 
 
-- 给guest_test用户赋予guest_test增删改的权限。第一个guest_test指数据库,第二个指用户名,hostname指指定ip
grant create,alter,drop on guest_test.* to guest_test@localhost
-- 给guest_test用户赋予guest_test库中所有表的全部权限
grant all privileges on *.* to guest_test@localhost

-- 给guest_test用户赋予guest_test库中所有表的查询权限
grant select on database.* to guest_test@localhost

-- 给guest_test用户赋予guest_test某个表的用户权限
grant select on guest_test.t1table to guest_test@localhost


3.撤销权限

撤销guest_test用户guest_test库所有表的增删改查的权限

revoke select,update,delete,insert on guest_test.* from guest_test@localhost;
flush privileges;

4.删除用户

drop user guest_test@localhost

5.在数据库中查询所有用户

SELECT * FROM mysql.user;