一:登录到mysql
mysql -h localhost -u root -p
二:创建
数据库和用户
1、mysql>create database books;
2、grant命令用来创建用户并赋予他们权限。语法如下
grant privileges[columns]
on item
to user_name[IDENTIFIED BY 'password']
[require ssl_options]
[WITH [GRANT OPTION| limit_options]]
3、revoke命令用来从一个用户收回权限。语法如下:
revoke privileges[(columns)]
on item
from user_name
注意:如果给出了with grant options子句,可以按如下方式撤销它(以及所有
其他权限)
revoke all privileges,grant
from user_name
实例:
创建一个管理员
mysql>grant all
->on *
-> to fred identified by‘123456’
-> with grant options;
撤销用户
mysql>revoke all privileges,grant
->from fred;
创建没有任何权限的用户
mysql>grant usage
->on books.*
->to sally identified by ‘123456’;
授予用户权限
mysql>grant select,insert,update,delete,index,alter,create,drop
->on books.*
->to sally;
减少用户权限
mysql>revoke alter,create,update
->on books.*
->from sally;
撤销所权限
mysql>revoke all
->on books.*
->from sally;