1、创建账户、权限控制
GRANT ALL PRIVILEGES on *.* to '用户名'@'主机' IDENTIFIED BY "密码" WITH GRANT OPTION;
flush privileges; -- 刷新使权限生效
- ALL PRIVILEGES : 授予全部权限, 也可以指定 select , insert , update , delete , create , drop , index , alter , grant , references , reload , shutdown , process , file 十四个权限。
-
. : 允许操作的数据库和表。
- 主机名:表示允许用户从哪个主机登录, % 表示允许从任意主机登录。
- WITH GRANT OPTION : 允许用户将自己拥有的权限授予别人。
- 8.0之后版本
CREATE USER `用户名`@`主机` IDENTIFIED BY '密码'; -- 创建账户
GRANT ALL ON *.* TO `用户名`@`主机` WITH GRANT OPTION; -- 授权
2、修改密码
update user set authentication_string=password('你的密码') where user="root"
或者
alter user '用户名'@'主机' identified with mysql_native_password by '你的密码';
3、查看权限
show grants; -- 查看当前用户的权限
show grants for '用户'@'主机'; -- 查看用户 abc 的权限
4、回收权限
revoke all privileges on *.* from '用户'@'主机'; -- 回收用户 abc 的所有权限
revoke grant option on *.* from '用户'@'主机'; -- 回收权限的传递
5、删除用户
drop user '用户名'@'主机';