本文实例,运行于 MySQL 5.0 及以上版本。

MySQL 赋予用户权限命令的简单格式可概括为:

grant 权限 on 数据库对象 to 用户
grant select on testdb.* to common_user@'%'grant insert on testdb.* to common_user@'%'grant update on testdb.* to common_user@'%'grant delete on testdb.* to common_user@'%'
grant select, insert, update, delete on testdb.* to common_user@'%'

grant 创建、修改、删除 MySQL 数据表结构权限。

grant create on testdb.* to developer@'192.168.0.%';grant alter on testdb.* to developer@'192.168.0.%';grant drop on testdb.* to developer@'192.168.0.%';
grant references on testdb.* to developer@'192.168.0.%';
grant create temporary tables on testdb.* to developer@'192.168.0.%';
grant index on testdb.* to developer@'192.168.0.%';
grant create view on testdb.* to developer@'192.168.0.%';grant show view on testdb.* to developer@'192.168.0.%';
grant create routine on testdb.* to developer@'192.168.0.%'; -- now, can show procedure statusgrant alter routine on testdb.* to developer@'192.168.0.%'; -- now, you can drop a proceduregrant execute on testdb.* to developer@'192.168.0.%';
grant all privileges on testdb to dba@'localhost'

四、grant 高级 DBA 管理 MySQL 中所有数据库的权限。

grant all on *.* to dba@'localhost'

1. grant 作用在整个 MySQL 服务器上:

grant select on *.* to dba@localhost; -- dba 可以查询 MySQL 中所有数据库中的表。grant all on *.* to dba@localhost; -- dba 可以管理 MySQL 中的所有数据库
grant select on testdb.* to dba@localhost; -- dba 可以查询 testdb 中的表。
grant select, insert, update, delete on testdb.orders to dba@localhost;
grant select(user_id,username) on smp.users to mo_user@'%' identified by '123345';grant select on smp.mo_sms to mo_user@'%' identified by '123345';
grant select(id, se, rank) on testdb.apache_log to dba@localhost;
grant execute on procedure testdb.pr_add to 'dba'@'localhost'grant execute on function testdb.fn_add to 'dba'@'localhost'

查看当前用户(自己)权限:

show grants;
show grants for dba@localhost;

revoke 跟 grant 的语法差不多,只需要把关键字 “to” 换成 “from” 即可:

grant all on *.* to dba@localhost;revoke all on *.* from dba@localhost;

1. grant, revoke 用户权限后,该用户只有重新连接 MySQL 数据库,权限才能生效。

2. 如果想让授权的用户,也可以将这些权限 grant 给其他用户,需要选项 “grant option“

grant select on testdb.* to dba@localhost with grant option;

更多相关文章

  1. Android(安卓)多模拟器使用adb shell
  2. Linux系统查看磁盘可用空间的5个命令
  3. Android(安卓)bluetooth介绍(四): a2dp connect流程分析
  4. Android(安卓)命令行编译、打包生成apk文件
  5. Ionic 运行报错No resource identifier found for attribute 'ap
  6. 使用sencha cmd创建android应用
  7. Android执行shell命令
  8. Android下模拟按键输入
  9. 【【【常用的ubuntu第三方工具及android命令(自存档)】】】二

随机推荐

  1. 用于检查用户名可用性的Javascript帖子无
  2. 管理大量文件的提示?
  3. PHP正则表达式
  4. PHP代码在不需要时在Javascript中自动运
  5. Web2.0 (social media) 企业应用的架构
  6. HTML5关于get请求添加headers的问题
  7. 在页面重新加载时添加活动链接和jquery幻
  8. 采集资源的方法(文字,图片) [图片]
  9. 如何将添加到ajax html编辑器的文本保存
  10. 在Chtmlview中,浏览多frame的框架的网页,有