mysql -uroot -p
2、创建用户
create user 'testuser1'@'%' identified by '123456';
这里表示创建一个不限制ip登录的用户 testuser1
该用户的密码是 123456
%代表不限制ip登录
flush privileges;
在本地新建连接都可以登录该用户了
这个时候你打开会发现只有information_schema一个数据库
3、给用户赋权
grant all privileges on test_grant.* to 'testuser1'@'%' with grant option;
这里表示给用户testuser1赋予数据库test_grant(这是我之前创建好的数据库)中所有表的所有权限
with grant option表示该用户可以给其他用户赋权,但是不能超过该用户的权限
这里的all privileges 可换成select,insert,update,delete,drop,create等
show grants for 'testuser1'@'%';
5、撤销用户权限
revoke all privileges on test_grant.* from 'testuser1'@'%';
这里表示撤销用户testuser1对数据库test_grant的所有 *** 作权限
注意:这里如果这么写,你会发现你打开还是有数据库test_grant(不过你无法 *** 作该数据库了),这是因为我之前创建的时候用到了with grant option,因为all privileges 是除了with grant option的所有权限
执行如下语句 回收用户所有权限即可revoke all privileges,grant option from 'testuser1'@'%';
6、删除用户
drop user 'testuser1'@'%';
7、查询所有用户及其权限
SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;
也可以这样
SELECT User, Host FROM mysql.user;
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)