- 查看所有用户
select distinct concat(user, '@', host,';') as userList from mysql.user;
select #查找
distinct #去重复
concat #拼接字符串
as #换个别名
- 查看当前登陆的是哪个用户
select user();
- 添加一个新用户
create user 'username'@'host' identified by 'passwd';
identified by #由...鉴别,这里是给这个用户添加个密码
- 给用户修改密码
set password for 'username'@'host' = password("123456");
- 删除用户
drop user 'username'@'host';
- 查看具体某个用户的权限
show grants for 'username'@'host';
- 给用户username的数据库databasename中的表tablename授select和insert权。
grant select, insert on databasename.tablename to 'username'@'host'
- 给username用户所有表授所有权
grant all on *.* to 'username'@'host';
- 撤销权限
revoke select on databasename.tablename from 'username'@'host';