MySQL使用者授權

2021-04-19 07:11:11 字數 2726 閱讀 6710

mysql使用者授權

grant 語句的語法如下:

grant privileges (columns)

on what

to user identifiedby "password"

with grant option

對使用者授權

mysql>grant rights on database.* to user@host

identified by "pass";

例1:增加乙個使用者test1密碼為abc,讓他可以在任何主機上登入,並對所有資料庫有查詢、插入、修改、刪除的許可權。

grant select,insert,update,delete on *.* to test1@"%

" identified by "abc";

on 子句中*.* 說明符的意思是「所有資料庫,所有的表」

例2:增加乙個使用者test2密碼為abc, 讓他只可以在localhost上登入,並可以對資料庫mydb進行查詢、插入、修改、刪除的操作。

grant select,insert,update,delete on mydb.* to test2@localhost

identified by "abc";

例子3增加乙個使用者custom,他能從主機localhost、server.domain和whitehouse.gov連線。他只想要從 localhost訪問bankaccount資料庫,從whitehouse.gov訪問expenses資料庫和從所有3臺主機訪問customer 資料庫。他想要從所有3臺主機上使用口令stupid。

為了使用grant語句設定個使用者的許可權,執行這些命令:

shell> mysql --user=root mysql

mysql> grant select,insert,update,delete,create,drop

on bankaccount.* to custom@localhost

identified by 'stupid';

mysql> grant select,insert,update,delete,create,drop

on expenses.*   to [email protected]

identified by 'stupid';

mysql> grant select,insert,update,delete,create,drop

on customer.* to custom@'%'

identified by 'stupid';

*********************************************=

許可權資訊用user、db、host、tables_priv和columns_priv表被儲存在mysql資料庫中(即在名為mysql的資料庫中)。

許可權            列                      context

select           select_priv          表                                     

insert           insert_priv          表

update         update_priv       表

delete           delete_priv         表

index            index_priv         表

alter             alter_priv            表

create          create_priv          資料庫、表或索引

drop             drop_priv            資料庫或表

grant            grant_priv           資料庫或表

references    references_priv    資料庫或表

reload           reload_priv          伺服器管理

shutdown     shutdown_priv        伺服器管理

process          process_priv           伺服器管理

file                  file_priv                 在伺服器上的檔案訪問

1.select、insert、update和delete許可權       

允許你在乙個資料庫現有的表上實施操作,是基本許可權

2.alter許可權允許你使用alter table

3.create和drop許可權允許你建立新的資料庫和表,或拋棄(刪除)現存的資料庫和表

如果你將mysql資料庫的drop許可權授予乙個使用者,該使用者能拋棄儲存了mysql訪問許可權的資料庫!

4.grant許可權允許你把你自己擁有的那些許可權授給其他的使用者。

你不能明顯地指定乙個給定使用者應該被拒絕訪問。即,你不能明顯地匹配乙個使用者並且然後拒絕連線。

你不能指定乙個使用者有權創建立或拋棄乙個資料庫中的表,也不能建立或拋棄資料庫本身。

可以同時列出許多被授予的單個許可權。

例如,如果想讓使用者能讀取和修改已有表的內容,但又不允許建立新錶或刪除表,可按如下授權:

grant select,insert,delete,update   on samp_db.*    to user@%

identifiedby "pass"

mysql 授權 mysql 使用者授權

mysql grant 許可權1,許可權2,許可權n on 資料庫名稱.表名稱 to 使用者名稱 使用者位址 identified by 連線口令 許可權1,許可權2,許可權n代表select,insert,update,delete,create,drop,index,alter,grant,re...

mysql授權使用者許可權 mysql授權使用者許可權

grant 普通資料使用者,查詢 插入 更新 刪除 資料庫中所有表資料的權利。grant select on testdb.to common user grant insert on testdb.to common user grant update on testdb.to common us...

mysql授權 MySQL使用者授權(GRANT)

當成功建立使用者賬戶後,還不能執行任何操作,需要為該使用者分配適當的訪問許可權。可以使用 show grant for 語句來查詢使用者的許可權。注意 新建立的使用者只有登入 mysql 伺服器的許可權,沒有任何其他許可權,不能進行其他操作。usage on 表示該使用者對任何資料庫和任何表都沒有許...