ºìÁªLinuxÃÅ»§
Linux°ïÖú

°²È«ÍøÂç·ÃÎÊmysqlÊý¾Ý¿â·þÎñÆ÷

·¢²¼Ê±¼ä:2006-04-20 09:54:33À´Ô´:ºìÁª×÷Õß:ccs
MySQL°²È«ÐÔϵͳÊÇÁé»îµÄ¡£ËüÔÊÐíÒÔÐí¶à²»Í¬µÄ·½·¨ÉèÖÃÓû§·ÃÎÊȨÏÞ¡£Í¨³££¬¿Éͨ¹ýGRANT ºÍREVOKE Óï¾äÀ´½øÐУ¬ÕâЩÓï¾ä¶Ô¿ØÖÆ¿Í»§»ú·ÃÎʵÄÊÚȨ±í½øÐÐÐ޸ġ£µ«ÊÇ£¬ÄúÓµÓеĿÉÄÜÊDz»Ö§³ÖÕâЩÓï¾äµÄ¾É°æ±¾MySQL£¨ÕâЩÓï¾äÔÚMySQL3.22.11ÒÔÇ°µÄ°æ±¾ÖÐûÓÐʹÓã©£¬»òÕß¿ÉÄÜ·¢¾õÓû§µÄȨÏÞºÃÏñ²»ÊÇ°´Ï£ÍûµØÔÚ¹¤×÷¡£¶ÔÓÚÕâÑùµÄÇé¿ö£¬Á˽âMySQLÊÚȨ±íµÄ½á¹¹ÒÔ¼°·þÎñÆ÷ÔõÑùʹÓÃËüÃÇÀ´¾ö¶¨·ÃÎÊÐí¿ÉȨÊÇÓаïÖúµÄ¡£ÄúÁ˽⵽ÕâÑùÒ»¸ö³Ì¶È£¬¾Í¿ÉÒÔͨ¹ýÖ±½ÓÐÞ¸ÄÊÚȨ±íÀ´Ôö¼Ó¡¢É¾³ý»òÐÞ¸ÄÓû§µÄȨÏÞ£¬»¹¿ÉÒÔÔÚ¼ì²é±íʱÕï¶ÏȨÏÞµÄÎÊÌâ¡£
±ÊÕß¼Ù¶¨ÄúÒѾ­ÔĶÁÁ˵Ú11Õµġ°Óû§Õ˺ŹÜÀí¡±Ò»½Ú£¬²¢Àí½âGRANT ºÍR E V O K EÓï¾äÊÇÔõÑù¹¤×÷µÄ¡£GRANT ºÍREVOKE ÌṩÁ˽¨Á¢MySQLÕ˺źÍÏà¹ØȨÏ޵ıãÀû·½·¨£¬µ«ÊÇ£¬ËüÃÇÖ»ÊÇÒ»¸öÇ°¶Ë¡£ËùÓÐÕæÕýµÄ²Ù×÷¶¼·¢ÉúÔÚMySQLÊÚȨ±íÖС£

MySQLÊÚȨ±íµÄ½á¹¹ºÍÄÚÈÝ

ÔÚÍøÂçÉÏÁ¬½Óµ½·þÎñÆ÷µÄ¿Í»§»ú¶ÔMySQLÊý¾Ý¿âµÄ·ÃÎÊÊÇÓÉÊÚȨ±íÄÚÈÝ¿ØÖƵġ£ÕâЩ±í¶¨Î»ÔÚmysqlÊý¾Ý¿âÖУ¬²¢ÔÚÊ״ΰ²×°MySQLµÄ¹ý³ÌÖнøÐгõʼ»¯£¨È總¼A ËùÃèÊöµÄ£©¡£±í12-1ºÍ±í12-2 ʾ³öÁÐÎå¸öÊÚȨ±í£¬ËüÃÇÊÇuser¡¢db¡¢host¡¢tables_priv ºÍc o l um n s _ priv¡£




ÊÚȨ±íµÄÄÚÈÝ°´ÏÂÁи÷ÏîʹÓãº
user user ±íÁгö¿ÉÁ¬½Óµ½·þÎñÆ÷ºÍ¿ÚÁîµÄÓû§£¬²¢Ö¸¶¨Óû§ÓµÓÐÄÄЩȫ¾Ö£¨³¬¼¶Óû§£©È¨ÏÞ£¨Èç¹ûÓеĻ°£©¡£ÈκÎÔÚuser ±íÏîÖÐËùÔÊÐíµÄȨÏÞ¶¼ÊÇÈ«¾ÖȨÏÞ£¬²¢ÊÊÓÃÓÚËùÓеÄÊý¾Ý¿â¡£ÀýÈ磬Èç¹ûÔÚÕâÀïÔÊÐíDELETE ȨÏÞ£¬ÔòÔÚ¸ÃÏîÖÐÁгöµÄÓû§¿É´ÓÈκαíÖÐɾ³ý¼Ç¼¡£Òò´Ë£¬ÔÚ½øÐÐÕâÏî²Ù×÷֮ǰǧÍòҪСÐÄ£¬Í¨³££¬×îºÃÔÚuser ±íÏîÖйرÕËùÓеÄȨÏÞ£¬¶øʹÓÃÆäËûµÄ¡¢Óиü¶àÏÞÖƵıíÀ´Ö¸¶¨È¨ÏÞ¡£¶Ô³¬¼¶Óû§£¨Èçr o o t£©ÔòÊÇÒ»¸öÀýÍ⣬µ«Ò»°ãºÜÉÙÓС£



db db ±íÁгöÊý¾Ý¿âÒÔ¼°ÄÄЩÓû§ÓµÓзÃÎÊÕâЩÊý¾Ý¿âµÄȨÏÞ¡£ÕâÀïÖ¸¶¨µÄȨÏÞÊÊÓÃÓÚÊý¾Ý¿âÖÐËùÓÐµÄ±í¡£
host host ±íÓëdb±í½áºÏʹÓã¬ÔÚ¸üϸµÄ¼¶±ðÉÏ¿ØÖƶÔÌض¨Ö÷»úµÄÊý¾Ý¿â·ÃÎÊȨÏÞ¡£¸Ã±í²»ÊÜGRANT ºÍREVOKE Óï¾äµÄÓ°Ï죬Òò´ËÄú»á·¢ÏÖ¸ù±¾²»»áȥʹÓÃËü¡£
tables_priv tables_priv ±íÖ¸¶¨±í¼¶µÄȨÏÞ¡£ÔÚÕâÀïËùÖ¸¶¨µÄȨÏÞÊÊÓÃÓÚ±íÖÐËùÓеÄÁС£
columns_priv columns_priv ±íÖ¸¶¨Á춵ÄȨÏÞ¡£ÔÚÕâÀïËùÖ¸¶¨µÄȨÏÞÊÊÓÃÓÚ±íÖÐÌض¨µÄÁС£
ÔÚ12 . 2 . 4½Ú¡°²»ÓÃGRANT ½¨Á¢Óû§¡±ÖУ¬ÎÒÃǽ«ÌÖÂÛGRANT Óï¾äÔõÑùÐÞ¸ÄÕâЩ±íÒÔ¼°ÔõÑùͨ¹ýÖ±½ÓÐÞ¸ÄÊÚȨ±íÀ´´ïµ½ÏàͬµÄ½á¹û¡£
tables_priv ºÍcolumns_priv ±íÊÇÔÚMySQL3.22.11ÖÐÒýÈëµÄ£¨ÓëGRANT Óï¾äͬʱ£©¡£Èç¹ûÄúÓµÓÐMySQLµÄ¾É°æ±¾£¬ÔòmysqlÊý¾Ý¿âÖ»ÓÐuser¡¢db ºÍhost ±í¡£Èç¹ûÒѾ­´Ó¾É°æ±¾Éý¼¶µ½3 . 2 2 . 11ÒÔÉϵİ汾£¬µ«ÈÔûÓÐtables_priv ºÍcolumns_priv ±íµÄ»°£¬¿ÉÔËÐÐmysql_fix_privileges_table ½Å±¾´´½¨ËüÃÇ¡£
ûÓÐrows_priv ±í£¬ÒòΪMySQL²»Ìṩ¼Ç¼¼¶µÄȨÏÞ¡£ÀýÈ磬²»ÄÜʹÓû§Ö»¾ÖÏÞÓÚijЩÁÐÖаüº¬Ä³¸öÖµµÄ±íÖеÄÄÇЩÐС£Èç¹ûÐèÒªÕâ¸öÄÜÁ¦£¬±ØÐë±àдӦÓóÌÐò¡£Èç¹ûÒªÏëÖ´ÐÐ×Éѯ¼Ç¼¼¶Ëø¶¨£¨advisory record-level locking£©£¬¿ÉÓø½Â¼C ÖнéÉܵÄGET_LOCK() º¯Êý½øÐС£
ÊÚȨ±íÖаüº¬Á½ÖÖÀàÐ͵ÄÁУº×÷ÓÃÓòÁУ¨ scope column£©ºÍȨÏÞÁУ¨ privilege column£©£¬Ç°Õß¾ö¶¨Ò»¸öÏîºÎʱ¿ÉÓ㬺óÕß¾ö¶¨Ò»¸öÏî¿ÉÊÚÓèÄÄЩȨÏÞ£¨ÓÐЩÊÚȨ±íÖаüº¬ÆäËû¸÷ʽ¸÷ÑùµÄÁУ¬µ«ÔÚÕâÀïÓëÎÒÃÇÎ޹أ©¡£

1. ÊÚȨ±íµÄ×÷ÓÃÓòÁÐ
ÊÚȨ±í×÷ÓÃÓòÁÐÖ¸¶¨±íÏîºÎʱʹÓá£Ã¿¸öÊÚȨ±íÏîÖж¼°üº¬User ºÍHost ÁУ¬ÒÔÖ¸Ã÷¸ÃÏîÔÚÌض¨µÄÓû§´ÓÌض¨µÄÖ÷»úÉÏÁ¬½ÓʱӦÓ㨠host ±íÊÇÒ»¸öÀýÍ⣬Ëü±»ÓÃÓÚÒ»ÖÖÌض¨µÄ¡¢ÎÒÃÇ»¹Î´½Ó´¥¹ýµÄ·½·¨ÖУ©¡£ÆäËû±íÖаüº¬¸½¼ÓµÄ×÷ÓÃÓòÁС£ÀýÈ磬 db ±íÖаüº¬Ò»¸öDb ÁÐÒÔÖ¸Ã÷¸ÃÏîÊÊÓÃÓÚÄĸöÊý¾Ý¿â¡£Í¬Ñù£¬ tables_priv ºÍcolumns_priv ±íÖаüº¬Ê¹¸Ã×÷ÓÃÓò¶ÔÊý¾Ý¿âÖÐÌض¨±í»ò±íÖеÄÁÐËõСµÄ×÷ÓÃÓò×ֶΡ£

2. ÊÚȨ±íȨÏÞÁÐ
ÊÚȨ±íÖл¹°üº¬È¨ÏÞÁС£ÕâЩÁÐÖ¸Ã÷ÁËÄÄЩȨÏÞ±»ÔÚ×÷ÓÃÓòÁÐÖÐÖ¸¶¨µÄÓû§ËùÓµÓС£MySQLÖ§³ÖµÄȨÏÞÏÔʾÔÚÒÔÏÂÁбíÖС£¸ÃÁбíʹÓÃÓÃÓÚGRANT Óï¾äµÄȨÏÞÃû¡£¶ÔÓڴ󲿷ÖÀ´Ëµ£¬ÔÚuser¡¢db ºÍhost ±íÖÐȨÏÞÁеÄÃû×ÖÓëÔÚµÚ11ÕÂÀûÓÃGRANT Óï¾äÁ¬½ÓÖÐËùÌÖÂÛµÄ
ȨÏÞÃûÏÔÈ»ÊÇÏàͬµÄ¡£ÀýÈ磬 Select_priv ÁжÔÓ¦ÓÚSELECT ȨÏÞ¡£

3. Êý¾Ý¿âºÍ±íµÄȨÏÞ
ÒÔÏÂȨÏÞÊÊÓÃÓÚÊý¾Ý¿âºÍ±íµÄ²Ù×÷£º
ALTER ÔÊÐíʹÓÃALTER TABLE Óï¾ä¡£Õâʵ¼ÊÉÏÊÇÒ»¸ö¼òµ¥µÄÒ»¼¶È¨ÏÞ£¬Äú±ØÐë¸ù¾Ý´òËãÓøñí×öʲôÒÔÓµÓÐÆäËûµÄȨÏÞ¡£
CREATE ÔÊÐí´´½¨Êý¾Ý¿âºÍ±í¡£Õâ¸öȨÏÞ²»ÔÊÐíÄú´´½¨Ë÷Òý¡£
DELETE ÔÊÐí´Ó±íÖÐɾ³ýÒÑÓмǼ¡£
DROP ÔÊÐíɾ³ýÊý¾Ý¿âºÍ±í¡£²»ÔÊÐíɾ³ýË÷Òý¡£
INDEX ÔÊÐí´´½¨»òɾ³ý±íµÄË÷Òý¡£
INSERT ÔÊÐíÔÚ±íÖвåÈëеļǼ¡£
REFERENCES δʹÓá£
SELECT ÔÊÐíÓÃSELECT Óï¾ä´Ó±íÖмìË÷Êý¾Ý¡£¸ÃȨÏÞ¶ÔÓÚ²»º¬±íµÄSELECT Óï¾äÊDz»±ØÒªµÄ£¬ÈçSELECT NOW() »òSELECT 4/2¡£
UPDATEÔÊÐíÐ޸ıíÖеÄÒÑÓмǼ¡£

4. ¹ÜÀíȨÏÞ
ÏÂÁÐȨÏÞÊÊÓÃÓÚ¿ØÖÆ·þÎñÆ÷²Ù×÷»òÓû§ÊÚȨÄÜÁ¦µÄ¹ÜÀí²Ù×÷£º
FILE ÔÊÐí·þÎñÆ÷ÔÚ·þÎñÆ÷Ö÷»úÉ϶ÁдÎļþ¡£¸ÃȨÏÞÈç¹ûûÓÐÕýµ±µÄÔ­ÒòÔò²»Ó¦ÊÚÓè,Èç12 . 2 . 3½Ú¡°ÊÚȨ±íÓ¦±ÜÃâµÄ·çÏÕ¡±ÖÐËùÊö£¬ËüÊÇΣÏյġ£·þÎñÆ÷²ÉȡijЩԤ·À´ëÊ©ÏÞ¶¨¸ÃȨÏÞÔÚÌض¨·¶Î§ÄÚʹÓá£ÄúÖ»¿ÉÒÔ¶ÁÊÀÈ˶¼¿É¶ÁµÄÎļþ£¬Òò´Ë²»ÐèÒª¿¼ÂÇÈκη½Ê½µÄ±£»¤¡£ÕýÔÚ½øÐÐд²Ù×÷µÄÎļþ²»ÔÊÐíÊÇÒѾ­´æÔڵġ£Õâ¿É·ÀÖ¹·þÎñÆ÷¸²¸ÇÖØÒªµÄÎļþ£¨Èç/ e t c / pass w d£©»òÊôÓÚÆäËûÓû§µÄÊý¾Ý¿âÎļþ¡£ÀýÈ磬Èç¹û²»Ê©¼Ó¸ÃÔ¼Êø£¬Äú¿ÉÄÜ»áÌ滻ȫ²¿mysqlÊý¾Ý¿âÖеÄÊÚȨ±íµÄÄÚÈÝ¡£
Èç¹ûÄúÊÚÓèFILE ȨÏÞ£¬¾Í²»ÄÜ×÷ΪUNIX µÄroot Óû§ÔËÐзþÎñÆ÷£¬ÒòΪroot ÄÜÔÚÎļþϵͳµÄÈκεط½´´½¨ÐµÄÎļþ¡£Èç¹û×÷ΪδÊÚȨÓû§ÔËÐзþÎñÆ÷£¬Ôò·þÎñÆ÷Ö»ÔÚ¸ÃÓû§¿É·ÃÎʵ½µÄĿ¼Öд´½¨Îļþ¡£
GRANT ÔÊÐí½«ÄúËùÓµÓеÄȨÏÞÊÚÓèÆäËûÓû§£¬ÆäÖаüÀ¨GRANT ȨÏÞ¡£
PROCESS ÔÊÐíͨ¹ýʹÓÃSHOW PROCESSLIST Óï¾ä»òmysqladmin processlist ÃüÁî²éѯÓйØÕýÔÚ·þÎñÆ÷ÖÐÔËÐеÄÏß³ÌÐÅÏ¢¡£¸ÃȨÏÞ»¹ÔÊÐíÀûÓÃKILL Óï¾ä»òmysqla d m i n kill ÃüÁîÈ¡ÏûÏ̡߳£ÄúʼÖÕ¿ÉÒԲ鿴»òÈ¡Ïû×Ô¼ºµÄÏ̡߳£PROCESS ȨÏÞÊÚÓèÄú¶ÔÈκÎÏ߳̽øÐÐÕâЩ²Ù×÷µÄÄÜÁ¦¡£
RELOAD ÔÊÐíÖ´ÐжàÖÖ·þÎñÆ÷¹ÜÀí²Ù×÷¡£¿É·¢²¼FLUSH SQL Óï¾ä£¬»¹¿ÉÖ´ÐÐmysqladmin µÄÃüÁîr e l o a d¡¢r e f r e s h¡¢f l us h - host s¡¢f l us h - l o g s¡¢flush-privileges ºÍf l us h - tables¡£
ͨ³£Õâ²»ÊÇÓÐΣÏÕµÄȨÏÞ£¬¾¡¹ÜËüʵ¼ÊÉÏÊǹÜÀíȨÏÞ¡£
SHUTDOWN ÔÊÐíÀûÓÃmysqladmin shutdown ¹Ø±Õ·þÎñÆ÷¡£
ÔÚuser¡¢db ºÍhost ±íÖУ¬Ã¿¸öȨÏÞ¶¼×÷Ϊµ¥¶ÀµÄÁиø³ö¡£ÕâЩÁж¼ÊÇÓÃENUM £¨¡°N¡±¡¢¡°Y¡±£©ÀàÐÍÉùÃ÷µÄ£¬Òò´ËËùÓÐȨÏÞµÄȱʡֵΪ¡°N¡± £¨o ff£©¡£tables_priv ºÍcolumns_priv ±íµÄȨÏÞÓÉSET Óï¾ä±íʾ£¬ËüÔÊÐíȨÏÞÒÔʹÓõ¥¸öÁеÄÈκÎ×éºÏÐÎʽָ¶¨¡£ÕâÁ½¸ö±í±ÈÆäËûÈý¸ö±íУ¬Õâ¾ÍÊÇΪʲôËüÃÇʹÓÃÁ˸üÓÐЧµÄ±íʾ·½·¨µÄÔ­Òò£¨user¡¢db ºÍhost ÓпÉÄÜÔÚ½«À´±»¸ÄÔ죬Ҳͨ¹ýSET À´±íʾȨÏÞ£©¡£
table_priv ±íµÄtable_priv Áж¨ÒåÈçÏ£º
SET ('Select ','Insert','update','Delete','Create','Drop','Grant','References','Index','alter')
columns_priv ±íµÄColumn_priv Áж¨ÒåÈçÏ£º
SET ('Select ','Insert','update','References')
ÁÐȨÏޱȱíȨÏÞÉٵö࣬ÒòΪÔÚÁм¶ÖÐÓÐÒâÒåµÄ²Ù×÷ºÜÉÙ¡£ÀýÈ磬Äú¿ÉÒÔ´´½¨Ò»¸ö±í£¬µ«²»ÄÜ´´½¨¹ÂÁ¢µÄÁС£
user ±íÖаüº¬¶ÔijЩȨÏÞµÄÁУ¬ÕâЩȨÏÞ²»³öÏÖÔÚÈκÎÆäËûÊÚȨ±íÖУ¬ÈçF i l e _ priv¡¢ P r o c e s s _ priv¡¢Reload_priv ºÍShutdown_priv ±í¡£ÕâЩȨÏÞÊÊÓÃÓÚÖ´ÐÐÓëÈκÎÌض¨Êý¾Ý¿â»òÓë±íÎ޹صķþÎñÆ÷µÄ²Ù×÷¡£ÀýÈ磬ʹÓû§¸ù¾Ýµ±Ç°Êý¾Ý¿â¹Ø±Õ·þÎñÆ÷ÊÇÎÞÒâÒåµÄ¡£
·þÎñÆ÷ÈçºÎ¿ØÖÆ¿Í»§»úµÄ·ÃÎÊ
ÔÚʹÓÃMySQLʱ£¬¿Í»§»ú·ÃÎÊ¿ØÖÆÓÐÁ½¸ö½×¶Î¡£µÚÒ»½×¶Î·¢ÉúÔÚÁ¬½Ó·þÎñÆ÷ʱ¡£·þÎñÆ÷²éÕÒuser ±í¿´¿´ÊÇ·ñÄܹ»ÕÒµ½ÓëÄúµÄÃû×Ö¡¢ÕýÔÚÁ¬½ÓµÄÖ÷»úÒÔ¼°ËùÌṩµÄ¿ÚÁîÏàÆ¥ÅäµÄÏî¡£Èç¹û²»Æ¥Å䣬Ôò²»ÄÜÁ¬½Ó¡£ÈôÆ¥Å䣬Ôò½¨Á¢Á¬½Ó£¬È»ºó¼ÌÐø½øÐеڶþ½×¶Î¡£Ôڴ˽׶ÎÖУ¬¶ÔÓÚÄú·¢²¼µÄÿ¸ö²éѯ£¬·þÎñÆ÷¶¼»á¼ì²éÊÚȨ±íÒԲ鿴ÄúÊÇ·ñ¾ßÓгä×ãµÄȨÏÞÀ´Ö´Ðиòéѯ¡£µÚ¶þ½×¶Î¼ÌÐø£¬Ö±µ½¹ØÓڸ÷þÎñÆ÷µÄ»á»°½áÊøΪֹ¡£

±¾½ÚÏêϸÌÖÂÛMySQLÓÃÀ´½«ÊÚȨ±íÏîÓëÊäÈëµÄ¿Í»§»úÁ¬½ÓÇëÇóºÍÓë²éѯÏàÆ¥ÅäµÄ¹æÔò¡£Õâ°üÀ¨ÔÚÊÚȨ±í×÷ÓÃÓòÁÐÖкϷ¨µÄÖµµÄÀàÐÍ¡¢ÔÚÊÚȨ±íÖÐȨÏÞÐÅÏ¢×éºÏµÄ·½·¨£¬ÒÔ¼°±íÏî¼ì²éµÄ´ÎÐò¡£

1. ×÷ÓÃÓòÁеÄÄÚÈÝ
ijЩ×÷ÓÃÓòÁÐÐèÒªÖ±½ÓÁ¿£¬µ«´ó¶àÊýÁÐÔÊÐíͨÅä·û»òÆäËûÌØÊâµÄÖµ¡£
Host ¸ÃÁÐÖµ¿ÉÒÔÊÇÒ»¸öÖ÷»úÃû»òÒ»¸öIP ºÅ¡£localhost ÖµµÄº¬ÒåÊDZ¾µØÖ÷»ú£¬µ«½öµ±Äúʵ¼ÊʹÓÃlocalhost Ö÷»úÖµ¶ø²»ÊÇʹÓøÃÖ÷»úÃûÁ¬½Óʱ²Å½øÐÐÆ¥Åä¡£¼Ù¶¨±¾µØÖ÷»úÃûΪp i t - v i per. s n a k e . n e t£¬ÇÒÔÚuser ±íÖÐÓÐÁ½¸öÏһ¸ö´øÓÐHost Öµ»òlocalhost£¬¶øÁíÒ»¸ö´øÓÐp i t - v i per.snake.net Öµ¡£´øÓÐlocalhost ÖµµÄÏî½öµ±ÄúÁ¬½Óµ½localhost ʱ²Å½øÐÐÆ¥Åä¡£ÁíÒ»¸öÏî½öµ±ÄúÁ¬½Óµ½p i t - v i per.snake.net ʱ²ÅÆ¥Åä¡£Èç¹ûÏëÈÃÓû§Äܹ»ÒÔÈÎÒâÒ»ÖÖ·½Ê½½øÐÐÁ¬½Ó£¬ÔÚuser ±íÖÐÐèÒªÁ½¸öÏî¡£»¹¿ÉÒÔÓÃͨÅä·ûÖ¸¶¨Host µÄÖµ¡£SQLµÄģʽ×Ö·û¡® %¡¯ºÍ¡® _¡¯Ò²¿ÉÒÔʹÓ㬲¢Óë²éѯÖеÄLIKE ²Ù×÷·ûÓÐÏàͬµÄº¬Òå¡£SQL ģʽ£¨²»ÔÊÐíREGEX ģʽ£©×Ö·û¿ÉÓÃÓÚÃû×ÖºÍIP ºÅ¡£ÀýÈ磬%.wise.edu½«Óëwise.eduÓòÖеÄÈκÎÖ÷»úÏàÅ䡣ͬÑù£¬ 192.168.% Óë192.168 ÀàB ×ÓÍøÖеÄÈκÎÖ÷»úÏàÅ䣬Òò¶ø192.168.3.% Óë192.168.3 ÀàC ×ÓÍøÖеÄÈκÎÖ÷»úÏàÅä¡£
Öµ¡®%¡¯×ÜÊÇÓëÈκÎÖ÷»úÏàÅ䣬ÓÃÓÚÔÊÐíij¸öÓû§´ÓÈκεط½½øÐÐÁ¬½Ó¡£¿Õ°×µÄH o s tµÄÖµÓë¡®%¡¯º¬ÒåÏàͬ£¨ÀýÍ⣺ÔÚdb ±íÖУ¬¿Õ°×µÄHost Öµº¬ÒåÊÇ¡°¼ì²éhost ±íµÄ½øÒ»²½µÄÐÅÏ¢¡±¡£
×ÔMySQL3.23 ÒÔÀ´£¬»¹¿ÉÒÔÀûÓñíÃ÷ÍøÂçºÅµÄ¶þ½øÖÆλÊýµÄÍøÂçÑÚÂëÖ¸¶¨IP ºÅ¡£ÀýÈ磬 192.168.128.0/17 Ö¸¶¨17 λµÄÍøÂçºÅ²¢ÓÃIP µØÖ·µÄÇ°17 λÖеÄ19 2 . 16 8 . 12 8ÓëËùÓÐÖ÷»úÏàÅä¡£
User Óû§Ãû±ØÐë»òÕßÊÇÖ±½ÓÁ¿»òÕßÊǿհ׵ģ¨¿Õ£©¡£¿Õ°×ÖµÓëÈκÎÓû§ÏàÅä¡£×÷ΪUser ÖµµÄ% ²»Òâζ×Å¿Õ°×£¬Ïà·´£¬ËüÓë´øÓÐ% µÄÖ±½ÓÃû×ÖµÄÓû§ÏàÅ䣬Õâ¿ÉÄܲ»ÊÇÄúÏëÒªµÄ¶«Î÷¡£
µ±Ò»¸öÊäÈëµÄÁ¬½Ó¶ÔÓ¦user ±í½øÐмì²é²¢ÇÒÏàÅäµÄÏî°üº¬Ò»¸ö¿Õ°×µÄUser ֵʱ£¬¿Í»§»ú±»ÈÏΪÊÇÄäÃûÓû§¡£
Password ¿ÚÁîÖµ»òÕßÊǿհ׵ģ¨¿Õ£©»òÕßÊǷǿյģ¬µ«²»ÔÊÐíͨÅä·û¡£¿Õ°×µÄ¿ÚÁî²¢²»ÊÇ˵ÓëÈκοÚÁîÏàÅä¡£ËüµÄÒâ˼ÊÇÓû§²»±ØÖ¸¶¨¿ÚÁî¡£¿ÚÁîÒÔ¼ÓÃÜÖµ¶ø²»ÊÇÒÔÖ±½ÓÖµ±»´æ´¢¡£Èç¹ûÔÚPassword Áд洢ÁËÒ»¸öÖ±½ÓµÄ¿ÚÁÔò¸ÃÓû§½«²»ÄÜÁ¬½Ó£¡GRANT Óï¾äºÍmysqladmin password ÃüÁî×Ô¶¯¶Ô¿ÚÁî½øÐмÓÃÜ£¬µ«ÊÇ£¬Èç¹ûʹÓÃÏñINSERT¡¢REPLACE¡¢UPDATE»òSET PASSWORD ÕâÑùµÄÓï¾ä£¬Ôò±ØÐëÓÃPA S S W O R D (¡°N E W _ PA S S W O R D¡±) ¶ø²»ÊǼòµ¥µØÓá°n e w _ pass w o r d¡± À´Ö¸¶¨¿ÚÁî¡£
Db ÔÚcolumns_priv ºÍtables_priv ±íÖУ¬Db Öµ±ØÐëÊÇÖ±½ÓµÄÊý¾Ý¿âÃû£¬²»ÔÊÐíģʽºÍ¿Õ°×Ãû¡£ÔÚdn ºÍhost ±íÖУ¬Db Öµ¿ÉÒÔÓÃÖ±½ÓÁ¿Ö¸¶¨£¬»òͨ¹ýʹÓÃÖ¸¶¨Í¨Åä·ûµÄSQL ģʽ×Ö·û¡®%¡¯»ò¡®_¡¯À´Ö¸¶¨¡£% Öµ»ò¿Õ°×½«ÓëÈκÎÊý¾Ý¿âÏàÅä¡£
Ta b l e _ name¡¢Column_name ÕâЩÁÐÖеÄÖµ±ØÐëÊÇÖ±½ÓÁ¿µÄ±íÃû»òÁÐÃû£¬Ä£Ê½ÖµºÍ¿Õ°×ÊDz»ÔÊÐíµÄ¡£
ÓÐЩ×÷ÓÃÓòÁÐÓÉ·þÎñÆ÷ÊÓΪÇø·Ö´óСдµÄ£¬ÆäËûµÄÔò²»ÊÇ¡£ÕâЩ¹æÔòÒÑÔÚ±í12 - 3ÖÐ×ܽᡣÌرð×¢Ò⣬ Table_name ֵʼÖÕÊÇÇø·Ö´óСдµÄ£¬¼´Ê¹²éѯÖеıíÃû´¦ÀíÊǸù¾Ý·þÎñÆ÷ÔËÐеÄÎļþϵͳ£¬Æä´óСдÃô¸ÐÐÔÒ²ÊÇÈç´Ë£¨ÔÚUNIX ÖÐÇø·Ö´óСд£¬¶øÔÚWindows Öв»Çø·Ö´óСд£©¡£



2. ²éѯ·ÃÎʼì²é
ÿµ±Äú·¢²¼²éѯʱ£¬·þÎñÆ÷¶¼Òª¼ì²éÄúÊÇ·ñÓÐ×ã¹»µÄȨÏÞÀ´Ö´Ðвéѯ¡£ËüÊÇͨ¹ýÒÀ´Î¼ì²éuser¡¢db¡¢table_priv ºÍcolumns_priv ±íÀ´½øÐеģ¬Ö±µ½ËüÈ·¶¨ÄúÓÐÊʵ±µÄ·ÃÎÊȨ»òͽȻµØËÑË÷ÁËËùÓеıíΪֹ¡£¸ü׼ȷµØ˵£º
1) ÔÚ¿ªÍ·½øÐÐÁ¬½ÓÒԲ鿴ËùÓµÓеÄÈ«¾ÖȨÏÞʱ£¬·þÎñÆ÷¼ì²éÏàÆ¥ÅäµÄuser ±íÏî¡£Èç¹ûÓÐÈ«¾ÖȨÏÞÇÒÂú×ã¸Ã²éѯ£¬Ôò·þÎñÆ÷Ö´Ðвéѯ¡£
2) Èç¹ûÈ«¾ÖȨÏÞ²»Âú×㣬Ôò·þÎñÆ÷ÔÚdb ±íÖÐÑ°ÕÒÒ»¸öÏ²¢½«¸ÃÏîµÄȨÏÞÔö¼Óµ½ÄúµÄÈ«¾ÖȨÏÞÖС£Èô½á¹ûÂú×ã¸Ã²éѯ£¬Ôò·þÎñÆ÷Ö´Ðвéѯ¡£
3) Èç¹ûÈ«¾ÖºÍÊý¾Ý¿â¼¶È¨ÏÞµÄ×éºÏ²»¹»£¬·þÎñÆ÷½«±£³Ö²»¶ÏµØ²éÕÒ£¬Ê×ÏÈÔÚtables _ priv ±íÖУ¬È»ºóÔÚcolumns_priv ±íÖвéÕÒ¡£
4) Èç¹ûÔÚËùÓбí¼ì²éºó·¢ÏÖÄúûÓÐÐí¿ÉȨ£¬·þÎñÆ÷½«¾Ü¾øÖ´Ðвéѯ¡£
¿ÚÁîÊÇÔõÑù´æ´¢ÔÚuser ±íÖеĿÚÁîÔÚuser ±íÖÐÒÔ¼ÓÃÜ´®µÄÐÎʽ³öÏÖ£¬Òò´ËÄú²»ÖªµÀÓû§µÄ¿ÚÁîÊÇʲô£¬¼´Ê¹ÒѾ­ÓµÓжԸñíµÄ·ÃÎÊȨҲÊÇÈç´Ë¡£Í¨³££¬ËƺõÈÏΪPA S S W O R D£¨£©º¯ÊýÖ´ÐÐÓëUNIX ¿ÚÁîËùʹÓõÄÀàÐÍÏàͬµÄ¼ÓÃÜ·½·¨£¬Æäʵ²¢²»ÊÇÕâÑùµÄ¡£
µ±Á½ÖÖ¼ÓÃÜ·½·¨Êǵ¥ÏòµÄÇÒ²»¿ÉÄæʱËüÃÇÊÇÏàͬµÄ£¬µ«ÊÇ£¬ MySQL²»Ê¹ÓÃÓëUNIX ÏàͬµÄ¼ÓÃÜËã·¨¡£ÕâÒâζ×Å£¬¼´Ê¹ÄúʹÓÃUNIX ¿ÚÁî×÷ΪMySQLµÄ¿ÚÁҲ±ðÏ£Íû¼ÓÃܵĿÚÁî´®ÏàÅä¡£Èç¹ûÏë¶ÔÓ¦ÓóÌÐòʹÓÃUNIX µÄ¼ÓÃÜ·½·¨£¬Ó¦Ê¹ÓÃC RYPT() º¯Êý¶ø·ÇPA S S W O R D ( )¡£
ÔÚÂß¼­Ìõ¼þÏ£¬ÊÚȨ±íÓÉ·þÎñÆ÷°´ÒÔÏÂÐÎʽʹÓãº
user OR db OR tables_priv OR columns_priv
Äú¿ÉÄÜÕýÔÚÆæ¹Ö£¬ÎªÊ²Ã´ÉÏÃæµÄÃèÊöÖ»Éæ¼°µ½Îå¸öÊÚȨ±íÖеÄËĸö¡£Õý»÷ÖÐÒªº¦£¬·þÎñÆ÷ʵ¼Ê¼ì²é·ÃÎÊÐí¿ÉȨµÄ·½·¨ÈçÏ£º
user OR (db AND host) OR tables_priv OR columns_priv
±ÊÕßÏȸø³öÁ˽ϼòµ¥µÄ±í´ïʽ£¬ÒòΪhost ±í²»ÊÜGRANT »òREVOKE Óï¾äµÄÓ°Ïì¡£Èç¹ûÒ»Ö±±£³ÖʹÓÃGRANT ºÍREVOKE À´¹ÜÀíÓû§È¨ÏÞ£¬½«²»ÐèÒª¿¼ÂÇhost ±í¡£µ«ÏÂÃ滹ÊǸø³öÁ˶ԸñíµÄÌÖÂÛ£¬ÒÔ±ãÄúÓÐËùÁ˽⣺
µ±·þÎñÆ÷¼ì²éÊý¾Ý¿â¼¶µÄȨÏÞʱ£¬Ëü²é¿´¿Í»§»úµÄdb ±íµÄÏî¡£Èç¹ûHost ÁÐÖµÊÇ¿Õ°×£¬Æ京ÒåÊÇ¡°¼ì²éhost ±í²éÕÒÄÄЩ·þÎñÆ÷¿É·ÃÎʸÃÊý¾Ý¿â¡±¡£
·þÎñÆ÷ÀûÓÃÓëÀ´×Ôdb ±íÏîÏàͬµÄDb ÁÐΪÏî²é¿´host ±í¡£Èç¹ûhost ±íÏîÓë¿Í»§»úÖ÷»ú²»ÏàÅ䣬¾Í²»ÊÚÓèÊý¾Ý¿â¼¶È¨ÏÞ¡£Èç¹ûÕâЩÏÓë¿Í»§»úÕýÔÚÁ¬½ÓµÄÖ÷»úµÄHost ÁÐÖµÏàÅ䣬Ôòdb ±íµÄÏîºÍhost ±íµÄÏî½øÐÐ×éºÏÒÔ²úÉú¿Í»§»úµÄÊý¾Ý¿â¼¶È¨ÏÞ¡£
µ«ÊÇ£¬È¨ÏÞÓÃÂß¼­AND ½øÐÐ×éºÏ£¬ÆäÒâ˼ÊÇ£¬³ý·Ç¿Í»§»úͬʱ³öÏÖÔÚÁ½¸öÏîÖУ¬·ñÔòËüûÓÐÖ¸¶¨µÄȨÏÞ¡£ÕâÑù£¬¿ÉÒÔÔÚ´Ëdb ±íÏîÖÐÊÚÓèÒ»×é»ù±¾µÄȨÏÞ£¬È»ºóÓÃhost±íÏîÓÐÑ¡ÔñµØ¶ÔÌض¨µÄÖ÷»ú½ûֹʹÓÃÕâЩȨÏÞ¡£ÀýÈ磬ÔÊÐí´ÓÓòµÄËùÓÐÖ÷»úÖзÃÎÊij¸öÊý¾Ý¿â£¬µ«ÊǶÔÓÚ¶¨Î»ÔÚ·Ç°²È«·¶Î§ÄÚµÄÖ÷»ú½ûֹʹÓÃÊý¾Ý¿âȨÏÞ¡£
ÒÔÉÏÃèÊöÎÞÒÉÒª½øÐзÃÎʼì²é£¬ÕâÌýÆðÀ´ºÃÏñÊÇÏ൱¸´ÔӵĹý³Ì£¬ÓÈÆäÊÇ¿¼Âǵ½·þÎñÆ÷ҪΪ¿Í»§»ú·¢²¼µÄÿһ¸öµ¥¶ÀµÄ²éѯ¼ì²éȨÏÞʱ¡£µ«ÊÇ£¬¸Ã¹ý³ÌÏ൱µØ¿ì£¬ÒòΪ·þÎñÆ÷²»¶Ôÿ¸ö²éѯʵ¼Ê¼ì²éÊÚȨ±íµÄÐÅÏ¢¡£Ïà·´£¬ÔÚ·þÎñÆ÷Æô¶¯Ê±£¬Ëü½«¸Ã±íµÄÄÚÈݶÁµ½ÄÚ´æÖУ¬È»
ºóÓÃÄÚ´æÖУ¨i n - m e m o r y£©µÄ¿½±´À´¼ìÑé²éѯ¡£Õâ¶ÔÓÚ·ÃÎʼì²é²Ù×÷ÐÔÄܲúÉúÁËÍƽø£¬µ«ÓÐÏ൱ÖØÒªµÄ¸ºÃæЧӦ£ºÈç¹ûÄúÖ±½ÓÐÞ¸ÄÁËÊÚȨ±íµÄÄÚÈÝ£¬Ôò·þÎñÆ÷½«²»»á×¢Ò⵽ȨÏ޵ĸı䡣
ÀýÈ磬Èç¹ûͨ¹ýÓÃINSERT Óï¾äÔö¼ÓÒ»¸öмǼµ½user ±íÖÐÀ´Ôö¼ÓÁËÒ»¸öÓû§£¬ÔÚ¸ÃÏîÖÐÖ¸¶¨µÄ¸ÃÓû§½«²»ÄÜÁ¬½Óµ½¸Ã·þÎñÆ÷¡£ÕâÊÇÃÔ»óйÜÀíÔ±µÄÎÊÌ⣨ÓÐʱ±È½ÏÓо­ÑéµÄ¹ÜÀíÔ±Ò²ÊÇÈç´Ë£©£¬µ«Êǽâ¾ö·½°¸ºÜ¼òµ¥£º¸æËß·þÎñÆ÷ÔÚÄúÐÞ¸ÄÊÚȨ±íºóÖØмÓÔØÆäÄÚÈݼ´¿É¡£¿ÉÒÔͨ¹ý·¢²¼FLUSH PRIVILEGES Óï¾ä»òͨ¹ýÖ´ÐÐmysqladmin flush-privileges £¨»òmysqladmin reload£¬Èç¹ûÊDz»Ö§³Öflush-privileges µÄ¾É°æ±¾µÄ»°£©À´½øÐС£

3. ×÷ÓÃÓòÁÐÆ¥Åä˳Ðò
MySQL·þÎñÆ÷ÒÔÒ»ÖÖÌض¨µÄ·½Ê½¶ÔÊÚȨ±íµÄÏî½øÐÐÅÅÐò£¬È»ºóÊÔ×Åͨ¹ý°´Ë³Ðò²é¿´ËùÓеÄÏîÀ´Æ¥ÅäÊäÈëµÄÁ¬½Ó¡£Ëù·¢ÏֵĵÚÒ»¸öÆ¥ÅäÈ·¶¨±»Ê¹ÓõÄÏî¡£ÖØÒªµÄÊÇÒªÀí½âMySQLʹÓõÄÅÅÐò˳Ðò£¬ÓÈÆäÊǶÔÓÚuser ±íµÄÅÅÐò¡£ÕâºÃÏóÊÇÔÚΪÄÑÊÔͼÀí½âMySQL°²È«ÐÔµÄÐí¶à
ÈËÃÇ¡£
µ±·þÎñÆ÷¶ÁÈ¡user ±íµÄÄÚÈÝʱ£¬Ëü¸ù¾ÝHost ºÍUser ÁеÄÖµ¶ÔÏî½øÐÐÅÅÐò¡£Host ÖµÊÇÓòÖµ£¨´øÓÐÏàͬHost ÖµµÄÏî±»Ò»Æð´æ·Å£¬È»ºó°´ÕÕUser Öµ½øÐÐÅÅÐò£©¡£µ«ÊÇ£¬ÅÅÐò²»ÊǴʵäʽµÄ£¬»ò²»ÍêÈ«ÊÇÕâÑùµÄ¡£Òª¼ÇסµÄÔ­ÔòÊÇÖ±½ÓÖµ±ÈģʽֵÓÅÏÈ¡£ÕâÒâζ×ÅÈç¹ûÕý´Ó
boa.snake.net ÖнøÐÐÁ¬½Ó²¢ÇÒ´øÓÐboa.snake.net ºÍ%.snake.net µÄHost Öµ£¬ÔòÖ±½ÓÖµ½«ÊÇÊ×Ñ¡µÄ¡£Í¬Ñù£¬ %.snake.net ÓÅÏÈÓÚ% . n e t£¬Èç´ËÀàÍÆ£¬%.net ÓÅÏÈÓÚ%¡£IP ºÅÒ²ÒÔÕâÖÖ·½·¨½øÐÐÆ¥Åä¡£¶ÔÓÚ´Ó´øÓÐ192.168.3.14 µÄIP ºÅµÄÖ÷»úÖÐÁ¬½ÓµÄ¿Í»§»ú£¬¾ßÓÐ19 2 . 16 8 . 3 . 4¡¢19 2 . 16 8 . 3 . %¡¢19 2 . 16 8 . %¡¢192.% ºÍ% µÄHost Öµ½«°´´Ë˳ÐòÆ¥Åä¡£

ÊÚȨ±íÓ¦±ÜÃâµÄ·çÏÕ

±¾½ÚÌÖÂÛÔÚÊÚȨʱӦ×ñÊصÄijЩԤ·À´ëÊ©ÒÔ¼°Î¬»¤ÈËÔ±×÷³öÇáÂÊÑ¡ÔñËùðµÄ·çÏÕ¡£Í¨³££¬¸øÓû§ÊÚ³¬¼¶Óû§È¨ÏÞÓ¦±£ÊØ¡£Ò²¾ÍÊÇ˵£¬²»ÒªÔÚuser ±íÖзÅÖÃȨÏÞ¡£È¡¶ø´úÖ®µÄÊÇʹÓÃÆäËûµÄÊÚȨ±íÀ´ÏÞÖÆÓû§¶ÔÌض¨Êý¾Ý¿â¡¢±í»òÁеÄȨÏÞ¡£user ±íÖеÄȨÏÞ¿ÉÁîÓû§Ó°Ïì·þÎñÆ÷µÄ²Ù×÷»ò·ÃÎÊÈκÎÊý¾Ý¿âÖеÄÈÎÒ»±í¡£
²»Òª¶ÔmysqlÊý¾Ý¿âÊÚȨ¡£¸ÃÊý¾Ý¿âÁ¬½ÓÊÚȨ±í£¬ÔÚ¸ÃÊý¾Ý¿âÉϾßÓÐȨÏÞµÄÓû§¿ÉÒÔÐÞ¸ÄÕâЩ±íÀ´»ñµÃÈκÎÆäËûÊý¾Ý¿âµÄȨÏÞ¡£ÔÊÐíÓû§ÐÞ¸ÄmysqlÊý¾Ý¿â±íµÄÊÚȨ»¹Äܸø¸ÃÓû§ÊÚÓèÒ»¸öÈ«¾ÖGRANT ȨÏÞ¡£Èç¹û¸ÃÓû§¿ÉÖ±½ÓÐÞ¸Ä±í£¬¾ÍÏ൱ÓÚ¿ÉÒÔ·¢²¼ÈκεÄGRANT
Óï¾ä¡£
FILE ÌØȨÏ൱ΣÏÕ,²»ÒªÇáÒ×ÊÚȨ¡£ÒÔÏÂÊÇÒ»¸öFILE ÌØȨÓû§µÄÀý×Ó£º
CREATE TABLE etc_passwd(pwd_entry TEXT);
LOAD DATA INFILE "/etc/passwd" INTO TABLE etc_passwd;
SELECT * FROM etc_passwd;
·¢²¼ÕâЩÓï¾äºó£¬¸ÃÓû§ÓµÓÐÄúµÄ¿ÚÁîÎļþµÄÄÚÈÝ¡£ÊÂʵÉÏ£¬ÔÚ·þÎñÆ÷ÖУ¬Èκι«ÓõĿɶÁÎļþµÄÄÚÈݶ¼¿ÉÒÔͨ¹ýÍøÂçÓÉÈκÎÓÐFILE ȨÏÞµÄÓû§·ÃÎÊ¡£
FILE ȨÏÞÒ²¿ÉÒÔÓÃÀ´¶ÔϵͳÖеġ¢²»ÄÜÓÃ×ã¹»µÄÏÞÖÆÎļþÐí¿ÉȨÀ´½¨Á¢µÄÊý¾Ý¿â½øÐÐÕÛÖÔ¡£Õâ¾ÍÊÇΪʲôӦ¸Ã½«Êý¾ÝĿ¼µÄÄÚÈÝÉèÖóÉΪֻÄÜÓÉ·þÎñÆ÷¿É¶ÁµÄÔ­Òò¡£Èç¹ûÓëÊý¾Ý¿â±íÏà¶ÔÓ¦µÄÎļþÊÇÈ«Çò·¶Î§ÄڿɶÁµÄ£¬Ôò²»½öÓи÷þÎñÆ÷Ö÷»úÕ˺ŵÄÓû§¿É¶ÁÈ¡ËüÃÇ£¬¶øÇÒÓÐFILE ȨÏÞµÄÈκοͻ§»úÒ²¶¼¿Éͨ¹ýÍøÂçÁ¬½Ó²¢¶ÁÈ¡ËüÃÇ£¡ÏÂÃæµÄ¹ý³Ì˵Ã÷ÈçºÎ½øÐдËÏî²Ù×÷£º
´´½¨ÓÐLONGBLOB ÁÐµÄ±í£º
USE test
CREATE TABLE tmp (b LONGBLOB)
Óô˱í¶ÁÈ¡ÄúÒªÇÔÈ¡µÄ±íµÄÿ¸öÎļþµÄÄÚÈÝ£¬È»ºó½«¸Ã±íµÄÄÚÈÝдµ½Äú×Ô¼ºµÄÊý¾Ý¿âÎļþÖУº



ÏÖÔÚ£¬ÄúÓÐÁËÒ»¸öбíy£¬Ëü°üº¬other_db.x µÄÄÚÈÝ£¬Äú¿ÉÒÔ¶ÔËü½øÐÐÍêÈ«·ÃÎÊ¡£
ΪÁ˱ÜÃâijÈËÓÃͬÑùµÄ·½Ê½¹¥»÷Äú£¬Ó¦¸ù¾Ý¡°ÄÚ²¿°²È«ÐÔ£º°²È«Êý¾ÝĿ¼·ÃÎÊ¡±µÄÖ¸µ¼ÉèÖÃÊý¾ÝĿ¼µÄÐí¿ÉȨ¡£µ±Æô¶¯·þÎñÆ÷ÒÔÏÞÖÆÓû§ÀûÓÃSHOW DATABASE ºÍS H O W TABLE S¶ÔËûÃDz»ÄÜ·ÃÎʵÄÊý¾Ý¿â½øÐзÃÎÊʱ£¬»¹¿ÉʹÓÃ-skip-show-database Ñ¡Ïî¡£Õ⽫ÓÐÖúÓÚ·ÀÖ¹Óû§²éÕÒ²»Ó¦·ÃÎʵÄÊý¾Ý¿âºÍ±í¡£
ALTER ȨÏÞ¿ÉÄÜÒÔÄúûÓÐÉèÏëµÄÈκη½·¨±»Ê¹Ó᣼ٶ¨ÄúÒªuser1ÄÜ·ÃÎÊtable1µ«²»ÄÜ·ÃÎÊt a b l e 2¡£µ«´øÓÐALTER ȨÏÞµÄÓû§¿ÉÄÜ»áͨ¹ýʹÓÃALTER TABLE ½«table2 ÖØÐÂÃüÃûΪtable1À´´òÂÒÄúµÄÕâÒ»ÉèÏë¡£
ҪСÐÄʹÓÃGRANT ȨÏÞ¡£Èç¹ûÁ½¸öÓû§Óв»Í¬µÄȨÏÞµ«¶¼¾ßÓÐGRANTȨÏÞ£¬ÔòËûÃÇÄÜʹ»¥ÏàµÄ·ÃÎÊȨ¸üÇ¿´ó¡£

²»ÓÃGRANT ½¨Á¢Óû§

Èç¹ûÊÇMySQL3.22.11ÒÔÇ°µÄ°æ±¾£¬Ôò²»ÄÜÓÃGRANT£¨»òR E V O K E£©Óï¾ä½¨Á¢Óû§ºÍ·ÃÎÊȨÏÞ£¬µ«ÊÇ¿ÉÒÔÖ±½ÓÐÞ¸ÄÊÚȨ±íµÄÄÚÈÝ¡£Èç¹ûÀí½âGRANT Óï¾äÊÇÔõÑùÐÞ¸ÄÊÚȨÓï¾äµÄ£¬Õâ¸öÎÊÌâ¾ÍºÜÈÝÒ×Àí½â¡£¿ÉÒÔͨ¹ýÊÖ¹¤·¢²¼INSERT Óï¾ä×Ô¼ºÀ´½øÐУ¨ INSERT Óï¾äºÜÄÑÕýÈ·ÊäÈ룬µ«ÕâÊÇÁíÍâµÄÎÊÌâ¡£ÊÂʵÉÏÕâ¸öÎÊÌâ¾ÍÊÇΪʲôGRANT Óï¾äÉè¼ÆµÃÈç´ËÒ×ÓÚʹÓõÄÔ­Òò£©¡£
µ±·¢²¼GRANT Óï¾äʱ£¬Ö¸¶¨ÁËÓû§ÃûºÍÖ÷»úºÅ£¬¿ÉÄÜ»¹Ö¸¶¨ÁË¿ÚÁî¡£user ±íÏî¶Ô¸ÃÓû§½¨Á¢£¬ÕâЩֵ¼Ç¼ÔÚ¸ÃÏîµÄU ser¡¢Host ºÍPassword ÁÐÖС£ÐèÒª×Ðϸ¿¼ÂǵÄÒ»¼þÊÂÊÇ£¬GRANT Óï¾ä¶Ô¿ÚÁî½øÐмÓÃÜ£¬¶øINSERT Ôò²»ÄÜ£¬ËüÐèÒªÓÃPASSWORD() º¯Êý¶ÔINSERTÓï¾äÖеĿÚÁî½øÐмÓÃÜ¡£
Èç¹ûÒѾ­Ö¸¶¨ÁËÊý¾Ý¿â¼¶µÄȨÏÞ£¬Óû§ÃûºÍÖ÷»úÃû½«¼Ç¼ÔÚdb ±íÏîµÄUser ºÍHost ÁÐÖС£ÒÑÊÚȨµÄÊý¾Ý¿â¼Ç¼ÔÚDb ÁÐÖУ¬ËùÊÚÓèµÄȨÏ޼ǼÔÚȨÏÞÁÐÖС£
¶ÔÓÚ±í¼¶ºÍÁм¶È¨ÏÞ£¬Ð§¹ûÊÇÀàËƵġ£ÔÚtables_priv ºÍcolumns_priv ±íÖд´½¨ÏîÀ´¼Ç¼Óû§Ãû¡¢Ö÷»úÃûºÍÊý¾Ý¿âÒÔ¼°ÐèÒªµÄ±í»òÕß±íºÍÁС£ÊÚÓèµÄȨÏ޼ǼÔÚȨÏÞÁÐÖС£
Èç¹û»¹¼ÇµÃÉÏÊöÌÖÂÛ£¬¼´Ê¹²»ÓÃGRANT Óï¾äÒ²Äܹ»½øÐÐGRANT µÄ¹¤×÷¡£Çë¼Çס£¬µ±Ö±½ÓÐÞ¸ÄÊÚȨ±íʱ£¬ÐèÒª¸æËß·þÎñÆ÷ÖØмÓÔØÊÚȨ±í£¬·ñÔòËü½«²»»áÁôÒâÕâЩ±ä»¯¡£¿ÉÒÔͨ¹ýÖ´ÐÐmysqladmin flush-privileges »òmysqladmin reload ÃüÁîÊ©¼ÓÖØмÓÔزÙ×÷¡£Èç¹ûÍü¼Ç
Õâ²½²Ù×÷£¬·þÎñÆ÷½«²»°´ÄúµÄÉèÏë½øÐй¤×÷¡£
ÒÔÏÂgrant Óï¾ä´´½¨ÓÐÈ«²¿È¨Ï޵ij¬¼¶Óû§£¬ÆäÖаüÀ¨ÏòÆäËûÓû§ÊÚȨµÄÄÜÁ¦£º
GRANT ALL ON *.* TO ethel@localhost IDENTFIEDBY "coffee" WITH GRANT OPTION
¸ÃÓï¾ä½«´´½¨user ±íµÄethel@localhost µÄÏ²¢¿ªÆôËùÓÐȨÏÞ£¬ÒòΪ³¬¼¶£¨È«¾Ö£©Óû§½«´æ´¢ÔÚÄÇÀï¡£ÓÃINSERT ½øÐÐͬÑù¹¤×÷µÄÓï¾äÊÇ£º



ÕâÊÇÒ»¸öºÜÄÑ¿´µÄINSERT Óï¾ä£¡ÄúÉõÖÁ»á·¢ÏÖËüÔÚÄúµÄMySQL°æ±¾Éϲ»¹¤×÷¡£ÊÚȨ±íµÄ½á¹¹¿ÉÄÜÒѾ­¸Ä±ä£¬ÔÚuser ±íÖпÉÄܲ»»áÓÐ14 ¸öȨÏÞÁС£´Ëʱ£¬Ó¦Ê¹ÓÃS H O W COLUMNS À´²éÕÒÿ¸öÊÚȨ±í°üº¬Ð©Ê²Ã´È¨ÏÞÁУ¬È»ºóµ÷ÕûINSERT Óï¾ä¡£
ÏÂÁÐGRANT Óï¾ä»¹´´½¨¾ßÓг¬¼¶Óû§×´Ì¬µÄÓû§£¬µ«ÊÇÖ»¶Ôµ¥¸öµÄȨÏÞ£º
GRANT ALL ON *.* TO flush@localhost IDENTFIEDBY "flushpass"
Äú¿ÉÄÜ»¹¼ÇµÃÎÒÃÇÔøÔÚµÚ11Õ½¨Á¢flush Óû§Ê±Ê¹Óùý¸ÃÓï¾ä¡£±¾ÀýÖеÄINSERT Óï¾ä±ÈÇ°Ò»¸ö¸ü¼òµ¥£¬¿ÉÒÔºÜÈÝÒ×µØÁгöÁÐÃû²¢Ö¸¶¨Î¨Ò»µÄÒ»¸öȨÏÞÁС£ËùÓÐÆäËûµÄÁж¼½«ÉèÖÃΪȱʡֵ¡°N¡±£º



Êý¾Ý¿â¼¶µÄȨÏÞÊÇÓÃON db_name.* ×Ó¾ä¶ø²»ÊÇÓÃON *.* ÊÚÓèµÄ£º
GRANT ALL ON samp_db.* TO boris@localhost IDENTFIEDBY "ruby"
ÕâЩȨÏÞ¶¼²»ÊÇÈ«¾ÖµÄ£¬Òò´Ë²»ÄÜ´æ´¢ÔÚuser ±íÖС£ÎÒÃÇÈÔÐèÒªÔÚuser ±íÖд´½¨Ò»¸öÏʹµÃÓû§¿ÉÒÔÁ¬½Ó£©£¬µ«ÎÒÃÇ»¹ÐèÒª´´½¨Ò»¸ödb ÏîÀ´¼Ç¼Êý¾Ý¿â¼¶µÄȨÏÞ£º



¡°N¡± ÁÐÊÇÕë¶ÔGRANT ȨÏ޵ģ¬¶ÔÓÚÔÚĩβ´øWITH GRANT OPTION µÄÊý¾Ý¿â¼¶µÄGRANT Óï¾ä£¬Ó¦¸Ã½«¸ÃÁÐÉèÖÃΪ¡°Y¡±¡£
ΪÁËÉèÖÃ±í¼¶»òÁм¶È¨ÏÞ£¬¶Ôtables_priv »òcolumns_priv ±íʹÓÃINSERT Óï¾ä¡£µ±È»£¬Èç¹ûûÓÐGRANT Óï¾ä£¬Ò²½«Ã»ÓÐÕâЩ±í£¬ÒòΪËüÃǶ¼ÊÇÔÚͬһʱ¼ä³öÏÖÔÚMySQL°æ±¾Öеġ£Èç¹ûÓÐÕâЩ±íµ«ÓÉÓÚijÖÖÔ­ÒòÏëÊÖ¹¤²Ù×ÝËüÃÇ£¬ÄÇôÄú²»ÄÜʹÓõ¥¸öµÄÁÐʹȨÏÞÓÐЧ¡£Äú»òÕßÉèÖÃtables _ priv. Table_priv »òÕßÉèÖÃc o l um n s _ priv.Column_priv Ϊһ¸öSET Öµ£¬¸ÃSET ÖµÓÉÄúÔÊÐíµÄȨÏÞ×é³É¡£ÀýÈ磬ΪÁËÔÊÐí¶Ôij¸ö±íµÄSELECT ºÍINSERT ȨÏÞ£¬Ó¦ÔÚÏà¶ÔµÄtables_priv ÏîÖÐÉèÖÃTable_priv ÁÐΪ¡°Select, Insert¡± Öµ¡£
Èç¹ûÒªÏëÐÞ¸Äij¸öÓû§µÄȨÏÞ£¨¸ÃÓû§µÄMySQLÕ˺ÅÒѾ­´æÔÚ£©£¬Ó¦Ê¹ÓÃUPDATE¶ø·ÇINSERT¡£ÎÞÂÛÊÇÔö¼Ó»¹ÊÇÈ¡ÏûȨÏÞ¶¼ÊÇÕâÑù¡£ÎªÁËɾ³ýÒ»¸öÍêÕûµÄÓû§£¬Ê¹ÓÃDELETE ´Ó¸ÃÓû§ËùÔÚµÄÿ¸öÊÚȨ±íÖÐɾ³ýÆäÏî¡£
Èç¹ûÒªÏë±ÜÃâ·¢²¼²éѯÀ´Ö±½ÓÐÞ¸ÄÊÚȨ±í£¬Ó¦¿´Ò»¿´ÓëMySQL·Ö·¢°üÒ»ÆðµÄmysqla c c e ssºÍmysql_setpermissions ½Å±¾¡£

Ò»¸öȨÏÞÄÑÌ⣬µÚ¶þ²¿·Ö

ÔÚµÚ11Õµġ°Ò»¸öȨÏÞÄÑÌ⣬µÚÒ»²¿·Ö¡±ÖУ¬ÎÒÃÇ¿´µ½ÁËÒ»ÖÖÊÚȨÇé¿ö£¬ÔÚÕâÖÖÇé¿öÖÐȨÏÞûÓÐÔ¤ÏëµÄЧ¹û¡£ÎÒÃÇÀ´¼òµ¥µØÐðÊöÒ»ÏÂÎÊÌ⣬¾­³£ÓëеÄMySQL°²×°Ò»Æð³öÏÖµÄÒ»¸öÎÊÌâÊǹÜÀíÔ±ÏëҪΪÓû§Ôö¼ÓÒ»ÏʹÓû§ÃÇ¿É´Ó¼¸¸öÖ÷»úÖнøÐÐÁ¬½Ó¡£ÕâÑù×ö×îÖ±½ÓµÄ·½·¨ÊÇʹÓðüº¬¡® %¡¯Í¨Åä·ûµÄÖ÷»úÃû˵Ã÷·û£¬Òò´Ë¹ÜÀíÔ±ÓÃÀàËÆÒÔϵÄÓï¾ä´´½¨Ò»¸öÓû§£º
GRANT ALL ON samp_db.* TO fred@%.snake.net IDENTFIEDBY "cocoa"
fred ÅöÇÉÓÐÒ»¸ö·þÎñÆ÷Ö÷»úµÄÕ˺ţ¬Òò´ËËûÊÔͼ´ÓÕâÀï½øÐÐÁ¬½Ó£º



Ϊʲô»áÕâÑù£¿ÎªÁ˼ÌÐøÀí½â£¬Äú±ØÐëͬʱ¿¼ÂÇmysql_install_db ÊÇÔõÑù½¨Á¢³õʼÊÚȨ±íºÍ·þÎñÆ÷ÔõÑùʹÓÃuser ±íµÄÏîÆ¥Åä¿Í»§»úÁ¬½ÓµÄ¡£µ±Í¨¹ýÔËÐÐmysql_ i n s t a l l _ db¶ÔÊý¾Ý¿â³õʼ»¯Ê±£¬Ëü´´½¨´øÓÐÈçÏÂHost ºÍUser ÖµµÄuser ±íµÄÏ



Ç°Á½Ïîͨ¹ýÖ¸¶¨localhost »òÖ÷»úÃûÔÊÐír o o tÁ¬½Óµ½±¾µØÖ÷»ú¡£ºóÁ½ÏîÔÊÐíÀ´×Ô±¾µØÖ÷»úµÄÄäÃûÁ¬½Ó¡£µ±Îªfred Ôö¼Ó´ËÏîʱ£¬Ôòuser ±í½«°üº¬ÕâЩÏ



µ±·þÎñÆ÷Æô¶¯Ê±£¬Ëü¶ÁÈ¡ÕâЩÏî²¢´æ´¢ËüÃÇ£¨ÏÈÖ÷»ú£¬È»ºóÊÇÖ÷»úµÄÓû§£©£¬Æä˳ÐòÊDZȽÏÏêϸµÄÖµÔÚÇ°£¬²»ÏêϸµÄÔÚºó£º





´ølocalhost µÄÁ½ÏîÒ»Æð´æ´¢£¬ÓÐroot µÄÄǸöÏî·ÅÔÚÇ°£¬ÒòΪÕâÏî±È¿Õ°×µÄ¸ü¾ßÌå¡¢¸üÏêϸ¡£´øÓÐp i t - v i per.snake.net µÄÏîÒÔÀàËƵķ½·¨Ò»Æð´æ´¢¡£ÕâЩÏÊDz»´øÈκÎͨÅä·ûµÄÖ±½ÓHost Öµ£¬Òò´ËËüÃǶ¼ÓÅÏÈÓÚfred µÄÏî½øÐд洢£¬¶øfred ÏîʹÓÃÁËÒ»¸öͨÅä·û¡£ÌرðµØ£¬ÄäÃûÓû§ÏîÔڴ洢˳ÐòÉÏÓÅÏÈÓÚfred µÄÏî¡£
´Ë½á¹ûÊÇ£¬µ±fred ÊÔͼ´Ó±¾µØÖ÷»úÉϽøÐÐÁ¬½Óʱ£¬´øÓпհ×Óû§ÃûµÄÏîÆ¥ÅäÏÈÓÚÔÚHost ÁÐÖаüº¬%.snake.net µÄÏî¡£¸ÃÏîµÄ¿ÚÁîÊǿհ׵ģ¬ÒòΪȱʡµÄÄäÃûÓû§Ã»ÓпÚÁî¡£ÓÉÓÚfred ÔÚÁ¬½Óʱָ¶¨ÁË¿ÚÁÔò²úÉúÒ»¸ö´íÎóÆ¥ÅäºÍ´íÎóÁ¬½Ó¡£
ÕâÀïÒª¼ÇסµÄÊÂÇéÊÇ£¬¾¡¹ÜʹÓÃͨÅä·ûÖ¸¶¨Óû§¿ÉÁ¬½ÓµÄÖ÷»úÕâÖÖ·½Ê½·Ç³£·½±ã£¬µ«Ö»ÒªÄúÔÚuser ±íÖб£ÁôÄäÃûÓû§£¬¾Í¿ÉÄÜ»á³öÏÖ´Ó±¾µØÖ÷»úÖÐÁ¬½ÓµÄÎÊÌâ¡£
ͨ³££¬±ÊÕß½¨Òéɾ³ýÄäÃûÓû§Ïî¡£Õ⽫ʹÄúµÄ¹¤×÷¸üÇáËÉһЩ£º
mysql> DELETE FROM user WHERE User="";
Èç¹ûÏë¸ü³¹µ×µÄ»°£¬¿É½«ÆäËûÊÚȨ±íµÄÄäÃûÓû§ÏîҲɾ³ý¡£ÓÐUser ÁеıíÊÇdb¡¢tables_priv ºÍc o l um n s _ priv¡£
±¾½Ú¸ø³öµÄÄÑÌâÊÇÒ»ÖÖÌØÊâµÄÇé¿ö£¬µ«°üº¬Á˸üΪÆÕ±éµÄÄÚÈÝ¡£Èç¹ûij¸öÓû§µÄȨÏÞ²»°´ËùÏ£ÍûµÄ·½Ê½¹¤×÷£¬Ôò¼ì²éÊÚȨ±í£¬¿´¿´ÊÇ·ñÓÐijЩÏî°üº¬Á˱ÈËùÌÖÂ۵ĸÃÓû§µÄÏî¸üÏêϸµÄHost Öµ£¬ÒÔ¼°ÊÔͼͨ¹ýÄǸöÓû§Æ¥ÅäÁ¬½ÓµÄHost Öµ¡£Èç¹ûÊÇÕâÑùµÄ£¬ÎÊÌâµÄÔ­Òò¿ÉÄܾÍÊÇËü¡£Äú¿ÉÄÜÐèҪʹ¸ÃÓû§µÄÏî¸üÏêϸ£¨»òÔö¼ÓÁíÒ»¸öÏîÀ´°üÀ¨¸üÏêϸµÄÇé¿ö£©¡£
ÎÄÕÂÆÀÂÛ

¹²ÓÐ 0 ÌõÆÀÂÛ