为数据库创建非root 用户

使用root 用户登录mysql

为数据库创建非root 用户,并分配相对应的权限

方法一:输入以下三条命令:

  1)create user xxx(用户名) identified by ‘xxxx(密码)’;

  创建用户账号xxx,密码xxxx(由identified by 指明)

  2)grant all on xxxx(数据库).* to 'xxx(用户名)'@‘%’;

  授权xxxx数据库下的所有表(xxxx.*)的所有权限(all)给用户xxx在以任何ip访问数据库的时候('xxx'@'%')(*代表所有表,也可以通过xxxx.xxx(表名)去指定特定的表,all 代表所有权限,也可以指定select、alter、drop、insert、update、create、delete等权限,%指任何ip,也可以指定localhost或者具体的ip,表示只允许本机或特定主机访问) 

  3)flush privileges;

  刷新权限

方法二:输入以下两条命令:

  1)grant all privileges on xxxx(数据库).* to 'xxx(用户名)'@‘%’ identified by ‘xxxx(密码)’;

  创建用户并授予所有权限

   2)flush privileges;

  刷新权限

查看用户有哪些权限

show grants for ”xxx(用户名)“@”localhost“;

修改用户权限

grant 权限名称 on xxx(数据库名) to ’xxx(用户名)‘@'%(主机)' with grant option;

flush privileges;

修改用户密码

update user set authentication_string=password('xxx(新密码)') where user = ‘xxx(用户名)’;

flush privileges;

删除用户(推荐使用方法一删除用户,如果方法一删除失败,再采用方法二)

方法一:

drop user 'xxx(用户名)'@‘%(主机)’;

flush privileges;

方法二:删除mysql数据库的user表中的数据

delete from user where user=‘xxx(用户名)’;

flush privileges;

=======================================================================

identified by     由...鉴定,以...鉴别

privileges  特权,权益;

猜你喜欢

转载自www.cnblogs.com/yungiu/p/10198691.html
今日推荐