mysql 許可權管理

來源:互聯網
上載者:User

標籤:

mysql更改使用者權限

This entry was posted by admin Monday, 26 April, 2010

1.“grant all on *.* to [email protected]’%’ identified by ‘yourpassword’;”——這個還可以順帶設定密碼。
2.“flush privileges; ”——重新整理一下,讓許可權生效。
mysql的一些其他的管理,可以用mysqladmin命令。可以用來設定密碼什麼的。

grant方面的詳細資料可以看我下面的轉載:
本文執行個體,運行於 MySQL 5.0 及以上版本。

MySQL 賦予使用者權限命令的簡單格式可概括為:

grant 許可權 on 資料庫物件 to 使用者

一、grant 普通資料使用者,查詢、插入、更新、刪除 資料庫中所有表資料的權利。

grant select on testdb.* to [email protected]’%’
grant insert on testdb.* to [email protected]’%’
grant update on testdb.* to [email protected]’%’
grant delete on testdb.* to [email protected]’%’

或者,用一條 MySQL 命令來替代:

grant select, insert, update, delete on testdb.* to [email protected]’%’

二、grant 資料庫開發人員,建立表、索引、視圖、預存程序、函數。。。等許可權。

grant 建立、修改、刪除 MySQL 資料表結構許可權。

grant create on testdb.* to [email protected]’192.168.0.%’;
grant alter on testdb.* to [email protected]’192.168.0.%’;
grant drop   on testdb.* to [email protected]’192.168.0.%’;

grant 操作 MySQL 外鍵許可權。

grant references on testdb.* to [email protected]’192.168.0.%’;

grant 操作 MySQL 暫存資料表許可權。

grant create temporary tables on testdb.* to [email protected]’192.168.0.%’;

grant 操作 MySQL 索引許可權。

grant index on testdb.* to [email protected]’192.168.0.%’;

grant 操作 MySQL 檢視、查看視圖原始碼 許可權。

grant create view on testdb.* to [email protected]’192.168.0.%’;
grant show   view on testdb.* to [email protected]’192.168.0.%’;

grant 操作 MySQL 預存程序、函數 許可權。

grant create routine on testdb.* to [email protected]’192.168.0.%’; — now, can show procedure status
grant alter routine on testdb.* to [email protected]’192.168.0.%’; — now, you can drop a procedure
grant execute        on testdb.* to [email protected]’192.168.0.%’;

三、grant 普通 DBA 管理某個 MySQL 資料庫的許可權。

grant all privileges on testdb to [email protected]’localhost’

其中,關鍵字 “privileges” 可以省略。
四、grant 進階 DBA 管理 MySQL 中所有資料庫的許可權。

grant all on *.* to [email protected]’localhost’

五、MySQL grant 許可權,分別可以作用在多個層次上。

1. grant 作用在整個 MySQL 伺服器上:

grant select on *.* to [email protected]; — dba 可以查詢 MySQL 中所有資料庫中的表。
grant all    on *.* to [email protected]; — dba 可以管理 MySQL 中的所有資料庫

2. grant 作用在單個資料庫上:

grant select on testdb.* to [email protected]; — dba 可以查詢 testdb 中的表。

3. grant 作用在單個資料表上:

grant select, insert, update, delete on testdb.orders to [email protected];

4. grant 作用在表中的列上:

grant select(id, se, rank) on testdb.apache_log to [email protected];

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 [email protected];

七、撤銷已經賦予給 MySQL 使用者權限的許可權。

revoke 跟 grant 的文法差不多,只需要把關鍵字 “to” 換成 “from” 即可:

grant all on *.* to   [email protected];
revoke all on *.* from [email protected];

八、MySQL grant、revoke 使用者權限注意事項

1. grant, revoke 使用者權限後,該使用者只有重新串連 MySQL 資料庫,許可權才會生效。

2. 如果想讓授權的使用者,也可以將這些許可權 grant 給其他使用者,需要選項 “grant option“

grant select on testdb.* to [email protected] with grant option;

這個特性一般用不到。實際中,資料庫許可權最好由 DBA 來統一管理。

Category: Post
You can follow any responses to this entry via RSS.
Comments are currently closed, but you can trackback from your own site.

=========================================================================


1.建立使用者並授權

grant語句的文法:

    grant privileges (columns) on what to user identified by "password" with grant option 
要使用該句型,需確定欄位有:

privileges 許可權指定符許可權允許的操作
    alter 修改表和索引
    create 建立資料庫和表
    delete 刪除表中已有的記錄
    drop 拋棄(刪除)資料庫和表
    index 建立或拋棄索引
    insert 向表中插入新行
    reference 未用
    select 檢索表中的記錄
    update 修改現存表記錄
    file 讀或寫伺服器上的檔案
    process 查看伺服器中執行的線程資訊或殺死線程
    reload 重載授權表或清空日誌、主機緩衝或表緩衝。
    shutdown 關閉伺服器
    all 所有;all privileges同義字
    usage 特殊的“無許可權”許可權

以上許可權分三組:

     第一組:適用於資料庫、表和列如:alter create delete drop index insert select update

     第二組:數系統管理權限 它們允許使用者影響伺服器的操作 需嚴格地授權 如:file process reload shut*

     第三組:許可權特殊 all意味著“所有許可權” uasge意味著無許可權,即建立使用者,但不授予許可權

columns

  許可權運用的列(可選)並且你只能設定列特定的許可權。如果命令有多於一個列,應該用逗號分開它們。

what

  許可權運用的層級。許可權可以是全域,定資料庫或特定表.

user

  許可權授予的使用者,由一個使用者名稱和主機名稱組成,許兩個同名使用者從不同地方串連.預設:mysql使用者password

  賦予使用者的口令(可選),如果你對使用者沒有指定identified by子句,該使用者口令不變.

    用identified by時,口令字串用改用口令的字面含義,grant將為你編碼口令.

      注:set password使用password()函數
with grant option

    使用者可以授予許可權通過grant語句授權給其它使用者(可選)

 

執行個體講解:

    grant all on db_book.* to [email protected] identified by "yeelion" 只能在本地串連

    grant all on db_book.* to [email protected] identified by "yeeliong" 允許從此域串連

    grant all on db_book.* to [email protected]% identified by "yeelion" 允許從任何主機串連

      注:"%"字元起萬用字元作用,與like模式比對的含義相同。

    grant all on db_book.* to [email protected]%.koowo.com identified by "yeelion";

      允許huaying從koowo.com域的任何主機串連

    grant all on db_book.* to [email protected] identified by "yeelion"

    grant all on db_book.* to [email protected]% identified by "yeelion"

    grant all on db_book.* to [email protected]/17 identified by "yeelion"

      允許從單IP 段IP或一子網IP登陸

      注:有時 使用者@IP 需用引號 如"[email protected]/17"

    grant all on *.* to [email protected] identified by "yeelion" with grant option

      添加超級使用者huaying 可在本地登陸做任何操作.

    grant reload on *.* to [email protected] identified by "yeelion" 只賦予reload許可權

    grant all on db_book to [email protected] indetified by "yeelion" 所有許可權

    grant select on db_book to [email protected]% indetified by "yeelion" 唯讀許可權

    grant select,insert,delete,update on db_book to [email protected] indetified by "yeelion"

      只有select,insert,delete,update的許可權

    grant select on db_book.storybook to [email protected] indetified by "yeelion" 只對錶

    grant update (name) on db_book.storybook to [email protected] 只對錶的name列 密碼不變

    grant update (id,name,author) on db_book.storybook to [email protected] 只對錶的多列

    grant all on book.* to ""@koowo.com 允許koowo.com域中的所有使用者使用庫book

 

    grant all on book.* to [email protected]%.koowo.com indetified by "yeelion" with grant option

      允許huaying對庫book所有表的管理員授權.

 

2.撤權並刪除使用者

revoke的文法類似於grant語句

    to用from取代,沒有indetifed by和with grant option子句. 如下:

    revoke privileges (columns) on what from user

    user:必須匹配原來grant語句的你想撤權的使用者的user部分。

    privileges:不需匹配,可以用grant語句授權,然後用revoke語句只撤銷部分許可權。

    revoke語句只刪許可權不刪使用者,撤銷了所有許可權後user表中使用者記錄保留,使用者仍然可以串連伺服器.

    要完全刪除一個使用者必須用一條delete語句明確從user表中刪除使用者記錄:

      delete from user where user="huaying"

      flush privileges; 重載授權表

        註:使用grant和revoke語句時,表自動重載,而你直接修改授權表時不是.

   http://www.cnblogs.com/llsun/archive/2013/08/06/3240963.html

 

    

mysql 許可權管理

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.