『壹』 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;