创建账号
#格式
create user '用户名'@'允许登录的地址' identified by '用户密码';
#创建本地登录账号
create user 'test'@'localhost' identified by '1234';
#创建远程登录账号
create user 'test'@'10.241.0.%' identified by '1234';
授权
#格式,
grant 权限 on 数据库.* to 用户名@登录主机 identified by '密码';
#给test用户授所有权现到mysql数据库,授权后需要刷新权限
grant all privileges on mysql.* to 'test'@'10.241.0.%' identified by '1234';
flush privileges;
#授权test用户拥有所有数据库的查询权限
grant select on *.* to 'test'@'10.241.0.%' identified by "1234";
#撤销用户权限
revoke all ON mysql.* from 'test'@'10.241.0.%';
权限分布 |
可能的设置的权限 |
表权限 |
‘Select’, ‘Insert’, ‘Update’, ‘Delete’, ‘Create’, ‘Drop’, ‘Grant’, ‘References’, ‘Index’, ‘Alter’ |
列权限 |
‘Select’, ‘Insert’, ‘Update’, ‘References’ |
过程权限 |
‘Execute’, ‘Alter Routine’, ‘Grant’ |
删除用户
#delete方法删除
delete from mysql.user where User='test' and Host='10.241.0.%';
flush privileges;
#drop方法删除
drop user 'test'@'10.241.0.%';
修改用户密码
update mysql.user set authentication_string=password('123456') where User='test' and Host='10.241.0.%';
flush privileges;