mysql 创建新用户并添加权限

1、添加用户
  1.1 添加一个新用户:
  
mysql>grant usage on *.* to 'sealy'@'localhost' IDENTIFIED by "123456" with grant option;

  上面这种只支持mysql服务器本地登录。

  1.2 添加一个任意Ip登录的用户:

mysql>grant usage on *.* to 'sealy'@'%' IDENTIFIED by "123456" with grant option;

 

2、授权test用户拥有testDB数据库的所有权限(某个数据库的所有权限):

  2.1 为某个用户授予所有权限:

mysql>grant all privileges on testDB.* to 'test'@'%' identified by '123456';

mysql>flush privileges;  --刷新系统权限表

  格式:grant 权限 on 数据库.* to 用户名@登录主机 identified by "密码"; 

  2.2 为某个用户授予部分权限:

mysql>grant select,update on 'testDB'.* to 'test'@'%' identified by '123456';
mysql>flush privileges; 

 

  2.5 授权test用户拥有所有数据库的某些权限:   

mysql>grant select,delete,update,create,drop on *.* to 'test'@'%' identified by "123456";

    --test用户对所有数据库都有select,delete,update,create,drop 权限。

  --@"%" 表示对所有非本地主机授权,不包括localhost。

  --对localhost授权:加上一句grant all privileges on testDB.* to 'test'@'localhost' identified by '123456';即可。

posted @ 2015-09-10 16:20  不笑猫  阅读(820)  评论(0编辑  收藏  举报