创建MySQL用户 赋予某指定库表的权限
摘自: http://renxiangzyq.iteye.com/blog/763837
update
ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value
建议使用GRANT语句进行授权,语句如下:
grant all privileges on *.* to root@'%' identified by "root";
---------------------------------------------------
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP
ON maildb.*
TO 'mail'@'localhost'
IDENTIFIED by 'mailPASSWORD ';
创建snort数据库,创建snort用户,将snort库所有表的所有权限赋予用户snort。 mysql> create database snort; Query OK, 1 row affected (0.06 sec) 创建数据库
mysql> use mysql; 进入mysql库 mysql> insert into user (Host,User,Password) values ("localhost","snort",PASSWORD("112233445566")); 创建用户,设置初始密码 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) 使改动生效; 注:如果不执行该指令,则无法正常执行后续指令。 mysql> grant all on snort.* to 'snort'@'localhost' ; Query OK, 0 rows affected (0.00 sec) 将snort库的所有权限赋予 snort用户 mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) 使改动生效 mysql> show grants for snort@localhost; +-------------------------------------------------------------------------------------+ | Grants for snort@localhost | +-------------------------------------------------------------------------------------+ | GRANT USAGE ON *.* TO 'snort'@'localhost' IDENTIFIED BY PASSWORD '1e6b29186dd45e97' | | GRANT ALL PRIVILEGES ON `snort`.* TO 'snort'@'localhost' | +-------------------------------------------------------------------------------------+ 2 rows in set (0.00 sec)
MySQL 赋予用户权限命令的简单格式可概括为:grant 权限 on 数据库对象 to 用户
一、grant 普通数据用户,查询、插入、更新、删除 数据库中所有表数据的权利。 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@'%'
或者,用一条 MySQL 命令来替代: grant select, insert, update, delete on testdb.* to common_user@'%'
二、grant 数据库开发人员,创建表、索引、视图、存储过程、函数。。。等权限。 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 操作 MySQL 外键权限。
grant references on testdb.* to developer@'192.168.0.%' ;
grant 操作 MySQL 临时表权限。
grant create temporary tables on testdb.* to developer@'192.168.0.%' ;
grant 操作 MySQL 索引权限。
grant index on testdb.* to developer@'192.168.0.%' ;
grant 操作 MySQL 视图、查看视图源代码 权限。
grant create view on testdb.* to developer@'192.168.0.%' ; grant show view on testdb.* to developer@'192.168.0.%' ;
grant 操作 MySQL 存储过程、函数 权限。
grant create routine on testdb.* to developer@'192.168.0.%' ; -- now, can show procedure status grant alter routine on testdb.* to developer@'192.168.0.%' ; -- now, you can drop a procedure grant execute on testdb.* to developer@'192.168.0.%' ; 三、grant 普通 DBA 管理某个 MySQL 数据库的权限。 grant all privileges on testdb to dba@'localhost' 其中,关键字 “privileges” 可以省略。
四、grant 高级 DBA 管理 MySQL 中所有数据库的权限。 grant all on *.* to dba@'localhost'
五、MySQL grant 权限,分别可以作用在多个层次上。 1. grant 作用在整个 MySQL 服务器上:
grant select on *.* to dba@localhost ; -- dba 可以查询 MySQL 中所有数据库中的表。 grant all on *.* to dba@localhost ; -- dba 可以管理 MySQL 中的所有数据库 2. grant 作用在单个数据库上:
grant select on testdb.* to dba@localhost ; -- dba 可以查询 testdb 中的表。
3. grant 作用在单个数据表上:
grant select, insert, update, delete on testdb.orders to dba@localhost ;
4. grant 作用在表中的列上:
grant select(id, se, rank) on testdb.apache_log to dba@localhost ;
5. grant 作用在存储过程、函数上:
grant execute on procedure testdb.pr_add to 'dba'@'localhost' grant execute on function testdb.fn_add to 'dba'@'localhost' 六、查看 MySQL 用户权限 查看当前用户(自己)权限:
show grants; 查看其他 MySQL 用户权限:
show grants for dba@localhost; 七、撤销已经赋予给 MySQL 用户权限的权限。 revoke 跟 grant 的语法差不多,只需要把关键字 “to” 换成 “from” 即可:
grant all on *.* to dba@localhost; revoke all on *.* from dba@localhost; 八、MySQL grant、revoke 用户权限注意事项 1. grant, revoke 用户权限后,该用户只有重新连接 MySQL 数据库,权限才能生效。
2. 如果想让授权的用户,也可以将这些权限 grant 给其他用户,需要选项 “grant option“
grant select on testdb.* to dba@localhost with grant option; 这个特性一般用不到。实际中,数据库权限最好由 DBA 来统一管理。
创建MySQL用户 赋予某指定库表的权限的更多相关文章
- 创建MySQL用户 赋予某指定库表的权限 flush privileges才能生效!!!!;@'localhost'授权本地,@'%'授权远程
update ERROR 1364 (HY000): Field 'ssl_cipher' doesn't have a default value 建议使用GRANT语句进行授权,语句如下: gra ...
- MySQL 如何只导出 指定的表 的表结构和数据 ( 转 )
MySQL 如何只导出 指定的表 的表结构和数据 ( 转 ) 2011-01-04 15:03:33 分类: MySQL MySQL 如何只导出 指定的表 的表结构和数据 导出更个库的表结构如下:my ...
- 12、创建mysql用户及赋予用户权限
1.通过help命令查看grant的用法: CREATE USER 'jeffrey'@'localhost' IDENTIFIED BY 'password'; GRANT ALL ON db1.* ...
- Mysql 5.6创建新用户并授权指定数据库相应权限
一.环境 Centos 6.9 Mysql 5.6.40 二.步骤 1.使用root用户登陆mysql mysql -uroot -p 输入密码: 2.创建新用户 CREATE USER 'user' ...
- 给新创建的用户 赋予所有的权利 *.* 查看权限 删除用户 ---------DCL用户权限管理篇
第一步:进入数据库以后,先用 show databases; 再use mysql; 再 show tables; 再 select user,host from mysql.user; ...
- oracle 创建一个用户,只能访问指定的对象
1>创建一个ORACLE 的用户 create user username identified by pws; 2>给用户授权 grant connect,resource to us ...
- MySQL给某个用户给某个库表设置权限
-- 用root(最高权限的用户)进行以下操作-- 创建数据库:emc_power CREATE DATABASE emc_power DEFAULT CHARACTER SET utf8 COLLA ...
- MySQL主从仅同步指定库
有两种方式,1.在主库上指定主库二进制日志记录的库或忽略的库: vim /etc/my.cnf ... binlog-do-db=xxxx 二进制日志记录的数据库 binlog-ignore-db=x ...
- linux下创建mysql用户和数据库,并绑定
Linux下输入命令: mysql -uroot -proot123 进入mysql后输入: 查看目前有哪些数据库存在:mysql> SHOW DATABASES; 创建数据库:create s ...
随机推荐
- 006 numpy常用函数
属于Numpy的函数. 一:通用函数 1.说明 是一种对ndarray中的数据执行元素级运算的函数. 2.一元函数 3.二元函数 二:矢量计算 1.numpy.where 主要有两种用法 np.whe ...
- Zookeeper三个监听案例
一.监听某一节点内容 /** * @author: PrincessHug * @date: 2019/2/25, 14:28 * @Blog: https://www.cnblogs.com/Hel ...
- Square Destroyer-POJ 1084 (IDA*)
Description The left figure below shows a complete 3*3 grid made with 2*(3*4) (=24) matchsticks. The ...
- JavaScript 作用域的误区
了解JavaScript的同学可能知道,JavaScript语言由于设计原因,导致语言本身存在很多先天性的不足,当然这并非设计者有意的,js语言最初是被设计来作为网页交互的脚本语言,依照现有的js语法 ...
- Spring AOP 切面编程实战Demo项目
为什么会有此项目?在某日,我看博客时,看到了讲面向切面编程的内容,之前也知道spring是面向切面编程的,只是自己没有写过相关的代码,于是决定自己写一个test.但是url拦截器从外部看,和AOP有相 ...
- shell下获取系统时间
shell下获取系统时间的方法直接调用系统变量 获取今天时期:`date +%Y%m%d` 或 `date +%F` 或 $(date +%y%m%d) 获取昨天时期:`date -d yesterd ...
- window下安装PIL
PIL非官方库64 友情连接: https://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/ ...
- (网络数据交互)Android解析Internet的Json资源文件
常用的Internet数据解析格式和工具: 网页显示的json数据如下: {"type":"FeatureCollection","metadata& ...
- 潭州课堂25班:Ph201805201 django 项目 第二十课 数据库分析设计图 (课堂笔记)
https://www.dbdesigner.net/
- rest framework 源码流程
1. def dispatch(self, request, *args, **kwargs): """ `.dispatch()` is pretty much the ...