当前位置:首页 » 数据仓库 » 数据库中grant
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

数据库中grant

发布时间: 2022-05-24 04:04:06

‘壹’ mysql这个列级权限用GRANT怎么写,高手来

mysql这个列级权限用GRANT怎么写
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@'%'
或者
grant select, insert, update, delete on testdb.* to common_user@’%’

‘贰’ 数据库的安全性 GRANT、REVOKE什么意思

首先什么是数据库安全
简单来说数据库允许你读取数据,修改。删除。插入。你才能对数据库中的数据进行这4个方面的操作.
那GRANT就是授权的语句只有对用户授权才能对数据库中的数据做. 读取.修改.删除.插入操作
REVOKE就是收回权限语句.那收回了你自然就没有权限再访问数据库的相关操作.
具体语句格式可以查下.

‘叁’ 数据库中的DROP,GRANT REVORK分别是干什么用的

数据库中的DROP是用来从数据库中删除已存在的表,或从表中删除已存在的索引。语法为DROP {TABLE表 | INDEX索引 ON表 | PROCEDURE procere | VIEW view}。

数据库中的GRANT是用来给某用户或某组或所有用户(PUBLIC)提供某些特定的权限。语法为GRANt <权限>[,<权限>]...[ON<对象类型><对象名>]TO<用户名>[,<用户名>]...[WITH GRANT OPTION]。

数据库中的REVORK是用来收回给某用户或某组或所有用户(PUBLIC)提供的某些权限。语法为REVOKE<权限>[,<权限>]...[ON<对象类型><对象名>] FROM<用户>[,<用户>]。

(3)数据库中grant扩展阅读:

数据库中使用DROP必须先关闭表,然后才能删除此表或此表中的索引。也可以使用 ALTER TABLE 语句 来删除表中的索引。对于非微软数据库, Microsoft Jet数据库引擎不支持DROP或 DDL 语句的使用。应采用 DAO Delete 方法。

数据库中除了创建者外,除非创建者赋予(GRANT)权限,其他人没有访问对象的权限。一旦用户有某对象的权限,他就可以使用那个特权。不需要给创建者赋予(GRANT)对象的权限,创建者自动拥有对象的所有权限,包括删除它的权限。

‘肆’ mysql grant 权限是什么权限

本文转自:DBAplus社群

Mysql 有多个个权限?经常记不住,今天总结一下,看后都能牢牢的记在心里啦!!

很明显总共28个权限:下面是具体的权限介绍:转载的,记录一下:


一.权限表

mysql数据库中的3个权限表:user、db、host

权限表的存取过程是:

1)先从user表中的host、user、password这3个字段中判断连接的IP、用户名、密码是否存在表中,存在则通过身份验证;

2)通过权限验证,进行权限分配时,按照useràdbàtables_privàcolumns_priv的顺序进行分配。即先检查全局权限表user,如果user中对应的权限为Y,则此用户对所有数据库的权限都为Y,将不再检查db,tables_priv,columns_priv;如果为N,则到db表中检查此用户对应的具体数据库,并得到db中为Y的权限;如果db中为N,则检查tables_priv中此数据库对应的具体表,取得表中的权限Y,以此类推。

二.MySQL各种权限(共27个)

(以下操作都是以root身份登陆进行grant授权,以p1@localhost身份登陆执行各种命令。)

1.usage

连接(登陆)权限,建立一个用户,就会自动授予其usage权限(默认授予)。

mysql>grantusageon*.*to‘p1′@’localhost’identifiedby‘123′;

该权限只能用于数据库登陆,不能执行任何操作;且usage权限不能被回收,也即REVOKE用户并不能删除用户。

2.select

必须有select的权限,才可以使用selecttable

mysql>grantselectonpyt.*to‘p1′@’localhost’;

mysql>select*fromshop;

3.create

必须有create的权限,才可以使用createtable

mysql>grantcreateonpyt.*to‘p1′@’localhost’;




4.createroutine

必须具有createroutine的权限,才可以使用{create|alter|drop}{procere|function}

mysql>grantcreateroutineonpyt.*to‘p1′@’localhost’;

当授予createroutine时,自动授予EXECUTE,ALTERROUTINE权限给它的创建者:

mysql>showgrantsfor‘p1′@’localhost’;

+—————————————————————————+

Grantsforp1@localhost

+————————————————————————–+

|GRANTUSAGEON*.*TO‘p1′@’localhost’IDENTIFIEDBYPASSWORD‘*′|

|GRANTSELECT,CREATE,CREATEROUTINEON`pyt`.*TO‘p1′@’localhost’|

|GRANTEXECUTE,ALTERROUTINEONPROCEDURE`pyt`.`pro_shop1`TO‘p1′@’localhost’|

+————————————————————————————-+

5.createtemporarytables(注意这里是tables,不是table)

必须有createtemporarytables的权限,才可以使用createtemporarytables.

mysql>.*to‘p1′@’localhost’;

[mysql@mydev~]$mysql-hlocalhost-up1-ppyt

mysql>createtemporarytablett1(idint);

6.createview

必须有createview的权限,才可以使用createview

mysql>grantcreateviewonpyt.*to‘p1′@’localhost’;

mysql>createviewv_shopasselectpricefromshop;

7.createuser

要使用CREATEUSER,必须拥有mysql数据库的全局CREATEUSER权限,或拥有INSERT权限。

mysql>grantcreateuseron*.*to‘p1′@’localhost’;

或:mysql>grantinserton*.*top1@localhost;

8.insert

必须有insert的权限,才可以使用insertinto…..values….

9.alter

必须有alter的权限,才可以使用altertable

(15);

10.alterroutine

必须具有alterroutine的权限,才可以使用{alter|drop}{procere|function}

mysql>grantalterroutineonpyt.*to‘p1′@’localhost‘;

mysql>dropprocerepro_shop;

QueryOK,0rowsaffected(0.00sec)


mysql>revokealterroutineonpyt.*from‘p1′@’localhost’;

[mysql@mydev~]$mysql-hlocalhost-up1-ppyt

mysql>dropprocerepro_shop;

ERROR1370(42000):‘p1′@’localhost’forroutine‘pyt.pro_shop’

11.update

必须有update的权限,才可以使用updatetable

mysql>updateshopsetprice=3.5wherearticle=0001anddealer=’A';

12.delete

必须有delete的权限,才可以使用deletefrom….where….(删除表中的记录)

13.drop

必须有drop的权限,才可以使用dropdatabasedb_name;droptabletab_name;

dropviewvi_name;dropindexin_name;

14.showdatabase

通过showdatabase只能看到你拥有的某些权限的数据库,除非你拥有全局SHOWDATABASES权限。

对于p1@localhost用户来说,没有对mysql数据库的权限,所以以此身份登陆查询时,无法看到mysql数据库:

mysql>showdatabases;

+——————–+

|Database|

+——————–+

|information_schema|

|pyt|

|test|

+——————–+

15.showview

必须拥有showview权限,才能执行showcreateview。

mysql>grantshowviewonpyt.*top1@localhost;

mysql>showcreateviewv_shop;

16.index

必须拥有index权限,才能执行[create|drop]index

mysql>grantindexonpyt.*top1@localhost;

mysql>createindexix_shoponshop(article);

mysql>dropindexix_shoponshop;

17.excute

执行存在的Functions,Proceres

mysql>callpro_shop1(0001,@a);

+———+

|article|

+———+

|0001|

|0001|

+———+

mysql>select@a;

+——+

|@a|

+——+

|2|

+——+

18.locktables

必须拥有locktables权限,才可以使用locktables

mysql>grantlocktablesonpyt.*top1@localhost;

mysql>locktablesa1read;

mysql>unlocktables;

19.references

有了REFERENCES权限,用户就可以将其它表的一个字段作为某一个表的外键约束。

20.reload

必须拥有reload权限,才可以执行flush[tables|logs|privileges]

mysql>grantreloadonpyt.*top1@localhost;

ERROR1221(HY000):

mysql>grantreloadon*.*to‘p1′@’localhost’;

QueryOK,0rowsaffected(0.00sec)

mysql>flushtables;

21.replicationclient

拥有此权限可以查询masterserver、slaveserver状态。

mysql>showmasterstatus;

ERROR1227(42000):Accessdenied;youneedtheSUPER,

mysql>grantReplicationclienton*.*top1@localhost;

或:mysql>grantsuperon*.*top1@localhost;

mysql>showmasterstatus;

+——————+———-+————–+——————+

|File|Position|Binlog_Do_DB|Binlog_Ignore_DB|

+——————+———-+————–+——————+

|mysql-bin.000006|2111|||

+——————+———-+————–+——————+

mysql>showslavestatus;

22.replicationslave

拥有此权限可以查看从服务器,从主服务器读取二进制日志。

mysql>showslavehosts;

ERROR1227(42000):Accessdenied;

mysql>showbinlogevents;

ERROR1227(42000):Accessdenied;

mysql>grantreplicationslaveon*.*top1@localhost;

mysql>showslavehosts;

Emptyset(0.00sec)

mysql>showbinlogevents;

+—————+——-+—————-+———–+————-+————–+

|Log_name|Pos|Event_type|Server_id|End_log_pos|Info|

+—————+——-+————–+———–+————-+—————+

|mysql-bin.000005|4|Format_desc|1|98|Serverver:5.0.77-log,Binlogver:4||mysql-bin.000005|98|Query|1|197|use`mysql`;createtablea1(iint)engine=myisam|

……………………………………

23.Shutdown

关闭MySQL:

[mysql@mydev~]$mysqladminshutdown

重新连接:

[mysql@mydev~]$mysql

ERROR2002(HY000):Can’‘/tmp/mysql.sock’(2)

[mysql@mydev~]$cd/u01/mysql/bin

[mysql@mydevbin]$./mysqld_safe&

[mysql@mydevbin]$mysql

24.grantoption

拥有grantoption,就可以将自己拥有的权限授予其他用户(仅限于自己已经拥有的权限)

mysql>grantGrantoptiononpyt.*top1@localhost;

mysql>grantselectonpyt.*top2@localhost;

25.file

拥有file权限才可以执行select..intooutfile和loaddatainfile…操作,但是不要把file,process,super权限授予管理员以外的账号,这样存在严重的安全隐患。

mysql>grantfileon*.*top1@localhost;

mysql>loaddatainfile‘/home/mysql/pet.txt’intotablepet;

26.super

这个权限允许用户终止任何查询;修改全局变量的SET语句;使用CHANGEMASTER,PURGEMASTERLOGS。

mysql>grantsuperon*.*top1@localhost;

mysql>purgemasterlogsbefore‘mysql-bin.000006′;

27.process

通过这个权限,用户可以执行SHOWPROCESSLIST和KILL命令。默认情况下,每个用户都可以执行SHOWPROCESSLIST命令,但是只能查询本用户的进程。

mysql>showprocesslist;

+—-+——+———–+——+———+——+——-+——————+

|Id|User|Host|db|Command|Time|State|Info|

+—-+——+———–+——+———+——+——-+——————+

|12|p1|localhost|pyt|Query|0|NULL|showprocesslist|

+—-+——+———–+——+———+——+——-+——————+

另外,

管理权限(如super,process,file等)不能够指定某个数据库,on后面必须跟*.*

mysql>grantsuperonpyt.*top1@localhost;

ERROR1221(HY000):

mysql>grantsuperon*.*top1@localhost;

QueryOK,0rowsaffected(0.01sec)

‘伍’ mysql grant 哪些权限

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@'%'
或者
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 procere status
grant alter routine on testdb.* to developer@’192.168.0.%’; — now, you can drop a procere
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;
这里在给一个用户授权多张表时,可以多次执行以上语句。例如:
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′;
4. grant 作用在表中的列上:
grant select(id, se, rank) on testdb.apache_log to dba@localhost;
5. grant 作用在存储过程、函数上:
grant execute on procere testdb.pr_add to ‘dba’@'localhost’
grant execute on function testdb.fn_add to ‘dba’@'localhost’

六、查看 MySQL 用户权限
查看当前用户(自己)权限:
show grants;
查看其他 MySQL 用户权限:
show grants for zhangkh@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授权表共有5个表:user、db、host、tables_priv和columns_priv。
授权表的内容有如下用途:
user表
user表列出可以连接服务器的用户及其口令,并且它指定他们有哪种全局(超级用户)权限。在user表启用的任何权限均是全局权限,并适用于所有数据库。例如,如果你启用了DELETE权限,在这里列出的用户可以从任何表中删除记录,所以在你这样做之前要认真考虑。
db表
db表列出数据库,而用户有权限访问它们。在这里指定的权限适用于一个数据库中的所有表。
host表
host表与db表结合使用在一个较好层次上控制特定主机对数据库的访问权限,这可能比单独使用db好些。这个表不受GRANT和REVOKE语句的影响,所以,你可能发觉你根本不是用它。

tables_priv表
tables_priv表指定表级权限,在这里指定的一个权限适用于一个表的所有列。
columns_priv表
columns_priv表指定列级权限。这里指定的权限适用于一个表的特定列。
注:
对于GRANT USAGE ON,查看手册有如下介绍和实例:
mysql> GRANT USAGE ON *.* TO ‘zhangkh’@'localhost’;
一个账户有用户名zhangkh,没有密码。该账户只用于从本机连接。未授予权限。通过GRANT语句中的USAGE权限,你可以创建账户而不授予任何权限。它可以将所有全局权限设为’N'。假定你将在以后将具体权限授予该账户。

‘陆’ grant命令属于sql的什么语言

sql本来就是一种语言啊,只是不同的数据库会在SQL的基础上进行优化,遣生成T-SQL,PL-SQL等各种语法而已。
而Grant 在SQL中只是一个授权的关键词而已。

‘柒’ MySQL:grant 语法详解(MySQL5.X)

本文实例,运行于MySQL5.0
及以上版本。
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
procere
status
grant
alter
routine
on
testdb.*
to
developer@'192.168.0.%';
--
now,
you
can
drop
a
procere
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'
五、MySQLgrant
权限,分别可以作用在多个层次上。
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
procere
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;
八、MySQLgrant、revoke
用户权限注意事项
1.
grant,
revoke
用户权限后,该用户只有重新连接MySQL
数据库,权限才能生效。
2.
如果想让授权的用户,也可以将这些权限grant
给其他用户,需要选项“grant
option“
grant
select
on
testdb.*
to
dba@localhost
with
grant
option;

这个特性一般用不到。实际中,数据库权限最好由DBA
来统一管理。

‘捌’ 数据库的安全性GRANT、REVOKE是什么意思

首先介绍什么是数据库安全。

简单来说数据库允许你读取数据,修改。删除。插入。你才能对数据库中的数据进行这4个方面的操作。

那GRANT就是授权的语句只有对用户授权才能对数据库中的数据做。读取、修改、删除、插入操作。

REVOKE就是收回权限语句.那收回了你自然就没有权限再访问数据库的相关操作。

‘玖’ 数据库:grant select on table S to A和 grant select on S to A 那个是对的,还是都对。。。

数据库中,grant select on S to A是正确的写法,grant select on table S to A则是错误的写法。

针对grant select on S to A的解释:

其中grant是授权,select是查询权限,S是被授权的表或视图名称,A是被授权的用户。

举例:

1、当没有给用户 user1分配查询(select)权限时,在查询分析器中用user1登陆数据库student,

其连最基本的查询操作都不能执行,截图如下:

‘拾’ SQL语言的GRANT和REVOKE语句主要是用来维护数据库的

选C,SQL语言的GRANT和REVOKE语句主要是用来维护数据库的安全性。

GRANT 和 REVOKE 两个语句分别是授予权限和回收权限语句,具有对 SQL语言的安全控制功能。

1、授权命令 grant,语法格式(SQL语句不区分大小写):Grant <权限> on 表名[(列名)] to 用户 With grant option

或 GRANT <权限> ON <数据对象> FROM <数据库用户>

//数据对象可以是表名或列名

//权限表示对表的操作,如select,update,insert,delete

2、注:授权命令是由数据库管理员使用的,若给用户分配权限时带With grant option子句,

则普通用户获权后,可把自己的权限授予其他用户。

(10)数据库中grant扩展阅读:

回收revoke

revoke语句:收回授予的权限

revoke一般格式:

revoke <权限> [,<权限>]…

on <对象类型 > <对象名> [,<对象类型 > <对象名>]..

from <用户> [,<用户>]…

[cascade | restrict];

例子:收回所有用户对表SC的查询权限

revoke select

on table sc

from public;