mysql 建立新用户并添加权限

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

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

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

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

 

二、受权test用户拥有testDB数据库的全部权限(某个数据库的全部权限):数据库

  2.1 为某个用户授予全部权限:服务器

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

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

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

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

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

 

  2.5 受权test用户拥有全部数据库的某些权限:   code

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

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

  --@"%" 表示对全部非本地主机受权,不包括localhost。it

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

相关文章
相关标签/搜索