mysql中创建的用户_MySQL中创建用户与授权

参考地址:http://blog.csdn.net/gebitan505/article/details/51726649

一.创建用户(使用root用户登录进入mysql命令行)

create user 'username'@'host' identified by 'password'

说明:

其中username为创建的用户名;

host为主机名,指定该用户在哪个主机上可以登陆,如果是本地用户可用localhost,如果想让该用户可以从任意远程主机登陆,可以使用通配符%;

password为用户密码,密码可以为空,如果为空则该用户可以不需要密码登陆服务器

例子:

1.create user 'xiong'@'localhost' identified by '123456' (xiong可以访问本地服务器)

2.create user 'ying'@'%' identified by '123456' (ying可以访问)

3.create user 'cai'@'%' identified by ''

4.create user 'he'@'%'

二.授予权限(使用root用户登录下)

grant privileges ondatabasename.tablename to'username'@'host'

说明:

1.privileges:用户的操作权限,如SELECT,INSERT,UPDATE等,如果要授予所的权限则使用ALL

2.databasename:数据库名

3.tablename:表名,如果要授予该用户对所有数据库和表的相应操作权限则可用*表示,如*.*

例子:

grant select,insert on test.user to 'xiong'@'localhost;(xiogn用户被授予test数据下user表的select和insert权限)

grant all privileges on *.* to 'ying'@'%' (ying用户被授予所有的数据库和数据表)

注意:

用以上命令授权的用户不能给其它用户授权,如果想让该用户可以授权,用以下命令:

grant privileges ondatabasename.tablename to'username'@'host' with grant option;

三.修改密码

set password for 'username'@'host' = password('newpassword');

如果是更改当前登录用户的密码:

set password = password('newpassword');

四.撤销用户权限

revoke privilege ondatabasename.tablename from'username'@'host';

说明:

privilege, databasename, tablename:同授权部分

例子:

revoke select on*.* from'ying'@'%';

revoke all privileges on *.* from 'ying'@'localhost'

注意:

假如你在给用户'ying'@'%'授权的时候是这样的(或类似的):grant select on test.user to 'ying'@'%',则在使用revoke select on *.* from 'ying'@'%';命令并不能撤销该用户对test数据库中user表的select 操作。相反,如果授权使用的是grant select on*.* to 'ying'@'%';则revoke select on test.user from 'ying'@'%';命令也不能撤销该用户对test数据库中user表的select权限。

具体信息可以用命令show grants for'ying'@'%'; 查看

五.删除用户

drop user 'username'@'host';

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值