| mysql更改用戶權限 This entry was posted by admin Monday, 26 April, 2010 1.“grant all on *.* to identified by ‘yourpassword’;”——這個還可以順帶設置密碼。       2.“flush privileges; ”——刷新一下,讓權限生效。      mysql的一些其他的管理,可以用mysqladmin命令。可以用來設置密碼什么的。 grant方面的詳細信息可以看我下面的轉載:本文實例,運行于 MySQL 5.0 及以上版本。 MySQL 賦予用戶權限命令的簡單格式可概括為: grant 權限 on數據庫對象 to用戶 一、grant普通數據用戶,查詢、插入、更新、刪除 數據庫中所有表數據的權利。 grant select, insert, update, delete on testdb.* to  二、grant數據庫開發人員,創建表、索引、視圖、存儲過程、函數。。。等權限。 grant 創建、修改、刪除 MySQL數據表結構權限。 grant create on testdb.* to ;grant alter on testdb.* to ;grant drop on testdb.* to ; grant 操作 MySQL外鍵權限。 grant references on testdb.* to ; grant 操作 MySQL臨時表權限。 grant create temporary tables on testdb.* to ; grant 操作 MySQL索引權限。 grant index on testdb.* to ; grant 操作 MySQL視圖、查看視圖源代碼 權限。 grant create view on testdb.* to ;grant show view on testdb.* to ; grant 操作 MySQL存儲過程、函數 權限。 grant create routine on testdb.* to ; — now, can show procedure statusgrant alter routine on testdb.* to ; — now, you can drop a proceduregrant execute on testdb.* to ; 三、grant普通 DBA 管理某個MySQL 數據庫的權限。 grant all privileges on testdb to  其中,關鍵字 “privileges” 可以省略。四、grant 高級DBA 管理 MySQL 中所有數據庫的權限。 grant all on *.* to  五、MySQL grant權限,分別可以作用在多個層次上。 1. grant 作用在整個 MySQL服務器上: grant select on *.* to ; — dba 可以查詢MySQL 中所有數據庫中的表。grant all on *.* to ; — dba 可以管理 MySQL中的所有數據庫 2. grant 作用在單個數據庫上: grant select on testdb.* to ; — dba 可以查詢 testdb 中的表。 3. grant 作用在單個數據表上: grant select, insert, update, delete on testdb.orders to ; 4. grant 作用在表中的列上: grant select(id, se, rank) on testdb.apache_log to ; 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 ; 七、撤銷已經賦予給 MySQL 用戶權限的權限。 revoke 跟 grant的語法差不多,只需要把關鍵字 “to”換成 “from”即可: grant all on *.* to ;revoke all on *.* from ; 八、MySQL grant、revoke用戶權限注意事項 1. grant, revoke 用戶權限后,該用戶只有重新連接 MySQL 數據庫,權限才能生效。 2. 如果想讓授權的用戶,也可以將這些權限grant 給其他用戶,需要選項“grant option“ grant select on testdb.* to 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 identified by "yeelion" 只能在本地連接 grant all on db_book.* to identified by "yeeliong" 允許從此域連接 grant all on db_book.* to identified by "yeelion" 允許從任何主機連接 注:"%"字符起通配符作用,與like模式匹配的含義相同。 grant all on db_book.* to identified by "yeelion"; 允許huaying從koowo.com域的任何主機連接 grant all on db_book.* to identified by "yeelion" grant all on db_book.* to identified by "yeelion" grant all on db_book.* to identified by "yeelion" 允許從單ip 段IP或一子網IP登陸 注:有時 用戶@IP需用引號 如"" grant all on *.* to identified by "yeelion" with grant option 添加超級用戶huaying 可在本地登陸做任何操作. grant reload on *.* to identified by "yeelion" 只賦予reload權限 grant all on db_book to indetified by "yeelion" 所有權限 grant select on db_book to indetified by "yeelion" 只讀權限 grant select,insert,delete,update on db_book to indetified by "yeelion" 只有select,insert,delete,update的權限 grant select on db_book.storybook to indetified by "yeelion" 只對表 grant update (name) on db_book.storybook to 只對表的name列 密碼不變 grant update (id,name,author) on db_book.storybook to 只對表的多列 grant all on book.* to ""@koowo.com 允許koowo.com域中的所有用戶使用庫book grant all on book.* to 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語句時,表自動重載,而你直接修改授權表時不是. |