linux mysql更改用戶權限


mysql更改用戶權限

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

1.“grant all on *.* to root@’%’ identified by ‘yourpassword’;”——這個還可以順帶設置密碼。
2.“flush privileges; ”——刷新一下,讓權限生效。
mysql的一些其他的管理,可以用mysqladmin命令。可以用來設置密碼什么的。

grant方面的詳細信息可以看我下面的轉載:
本文實例,運行於 MySQL 5.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 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 來統一管理。

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 huaying@koowo.com identified by "yeelion" 只能在本地連接

    grant all on db_book.* to huaying@vpn.koowo.com identified by "yeeliong" 允許從此域連接

    grant all on db_book.* to huaying@% identified by "yeelion" 允許從任何主機連接

      注:"%"字符起通配符作用,與like模式匹配的含義相同。

    grant all on db_book.* to huaying@%.koowo.com identified by "yeelion";

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

    grant all on db_book.* to huaying@192.168.1.189 identified by "yeelion"

    grant all on db_book.* to huaying@192.168.1.% identified by "yeelion"

    grant all on db_book.* to huaying@192.168.1.0/17 identified by "yeelion"

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

      注:有時 用戶@IP 需用引號 如"huaying@192.168.1.0/17"

    grant all on *.* to huaying@localhost identified by "yeelion" with grant option

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

    grant reload on *.* to huaying@localhost identified by "yeelion" 只賦予reload權限

    grant all on db_book to huaying@koowo.com indetified by "yeelion" 所有權限

    grant select on db_book to huaying@% indetified by "yeelion" 只讀權限

    grant select,insert,delete,update on db_book to huaying@koowo.com indetified by "yeelion"

      只有select,insert,delete,update的權限

    grant select on db_book.storybook to huaying@localhost indetified by "yeelion" 只對表

    grant update (name) on db_book.storybook to huaying@localhost 只對表的name列 密碼不變

    grant update (id,name,author) on db_book.storybook to huaying@localhost 只對表的多列

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

 

    grant all on book.* to huaying@%.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語句時,表自動重載,而你直接修改授權表時不是.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM