- #访问控制
- ## 登录 mysql
- mysql -u root -p
- ## 查看所有用户
- select user from mysql.user
- ## 创建用户
- CREATE USER username@host IDENTIFIED BY password;
- ## 删除用户
注意必须明确给出该账号的主机名
- drop user test@localhost;
- ## 重命名用户
- rename user test@localhosttofoo@localhost;
- ## 修改密码
- set password for test@localhost=password(hello);
- # 权限管理
- ## 查看权限
- show grants for test@localhost;
- ## 授权
- grant select(cust_id,cust_name)
- on mysql_test.customers
tozhangsan@localhost;-- 授予在数据库 mysql_test 的表 customers 上拥有对列 cust_id 和列 cust_name 的 select 权限
- grant select ,update
- on mysql_test.customers
to liming@localhostidentified by123;-- 新建一个用户为 liming, 并授予其在数据库 mysql_test 的表 customers 上拥有 select 和 update 的权限
- grant all
- on mysql_test.*
tozhangsan@localhost;-- 授予可以在数据库 mysql_test 中执行所有操作的权限
- grant create user
- on *.*
tozhangsan@localhost;-- 授予系统中已存在用户 zhangsan 拥有创建用户的权限
- ## 权限的转移
- grant select,update
- on mysql_test.customers
- tozhou@localhostidentified by123
- with grant option;
如果上面 with 子句后面跟的是
- max_queries_per_hour count
- max_updates_per_hour count
- max_connections_per_hour count
- max_user_connections count
中的某一项, 则该 grant 语句可用于限制权限
- grant delete
- on mysql_test.customers
- to zhangsan@localhost
with max_queries_per_hour 1;-- 每小时只能处理一条 delete 语句的权限
- ## 权限的撤销
- revoke select
- on mysql_test.customers
fromzhangsan@localhost;-- 回收用户 zhangsan 在数据库 mysql_test 的表 customers 上的 select 权限
来源: http://www.bubuko.com/infodetail-2509770.html