»áÔ±£º ÃÜÂ룺 ¡¡Ãâ·Ñ×¢²á | Íü¼ÇÃÜÂë | »áÔ±µÇ¼ ÍøÒ³¹¦ÄÜ£º ¼ÓÈëÊÕ²Ø ÉèΪÊ×Ò³ ÍøÕ¾ËÑË÷  
 °²È«¼¼Êõ¼¼ÊõÎĵµ
  ¡¤ °²È«ÅäÖÆ
  ¡¤ ¹¤¾ß½éÉÜ
  ¡¤ ºÚ¿Í½Ìѧ
  ¡¤ ·À»ðǽ
  ¡¤ Â©¶´·ÖÎö
  ¡¤ ÆƽâרÌâ
  ¡¤ ºÚ¿Í±à³Ì
  ¡¤ ÈëÇÖ¼ì²â
 °²È«¼¼ÊõÂÛ̳
  ¡¤ °²È«ÅäÖÆ
  ¡¤ ¹¤¾ß½éÉÜ
  ¡¤ ·À»ðǽ
  ¡¤ ºÚ¿ÍÈëÇÖ
  ¡¤ Â©¶´¼ì²â
  ¡¤ Æƽⷽ·¨
  ¡¤ É±¶¾×¨Çø
 °²È«¼¼Êõ¹¤¾ßÏÂÔØ
  ¡¤ É¨Ã蹤¾ß
  ¡¤ ¹¥»÷³ÌÐò
  ¡¤ ºóÃÅľÂí
  ¡¤ ¾Ü¾ø·þÎñ
  ¡¤ ¿ÚÁîÆƽâ
  ¡¤ ´úÀí³ÌÐò
  ¡¤ ·À»ðǽ
  ¡¤ ¼ÓÃܽâÃÜ
  ¡¤ ÈëÇÖ¼ì²â
  ¡¤ ¹¥·ÀÑÝʾ
°²È«·ÀÏß > °²È«ÅäÖÆ
MySQL°²È«ÐÔÖ¸ÄÏ
·¢±íÈÕÆÚ£º2003-08-12 00:00:00×÷Õߣºê ³ö´¦£º  

×÷Ϊһ¸öMySQLµÄϵͳ¹ÜÀíÔ±£¬ÄãÓÐÔðÈÎά»¤ÄãµÄMySQLÊý¾Ý¿âϵͳµÄÊý¾Ý°²È«ÐÔºÍÍêÕûÐÔ¡£±¾ÎÄÖ÷ÒªÖ÷Òª½éÉÜÈçºÎ½¨Á¢Ò»¸ö°²È«µÄMySQLϵͳ£¬´ÓϵͳÄÚ²¿ºÍÍⲿÍøÂçÁ½¸ö½Ç¶È£¬ÎªÄãÌṩһ¸öÖ¸ÄÏ¡£

±¾ÎÄÖ÷Òª¿¼ÂÇÏÂÁа²È«ÐÔÓйصÄÎÊÌ⣺

Ϊʲô°²È«ÐÔºÜÖØÒª£¬ÄãÓ¦¸Ã·À·¶ÄÇЩ¹¥»÷£¿

·þÎñÆ÷ÃæÁٵķçÏÕ£¨ÄÚ²¿°²È«ÐÔ£©£¬ÈçºÎ´¦Àí£¿

Á¬½Ó·þÎñÆ÷µÄ¿Í»§¶Ë·çÏÕ£¨Íⲿ°²È«ÐÔ£©£¬ÈçºÎ´¦Àí£¿

MySQL¹ÜÀíÔ±ÓÐÔðÈα£Ö¤Êý¾Ý¿âÄÚÈݵݲȫÐÔ£¬Ê¹µÃÕâЩÊý¾Ý¼Ç¼ֻÄܱ»ÄÇЩÕýÈ·ÊÚȨµÄÓû§·ÃÎÊ£¬ÕâÉæ¼°µ½Êý¾Ý¿âϵͳµÄÄÚ²¿°²È«ÐÔºÍÍⲿ°²È«ÐÔ¡£

ÄÚ²¿°²È«ÐÔ¹ØÐĵÄÊÇÎļþϵͳ¼¶µÄÎÊÌ⣬¼´£¬·ÀÖ¹MySQLÊý¾ÝĿ¼£¨DATADIR£©±»ÔÚ·þÎñÆ÷Ö÷»úÓÐÕ˺ŵÄÈË£¨ºÏ·¨»òÇÔÈ¡µÄ£©½øÐй¥»÷¡£Èç¹ûÊý¾ÝĿ¼ÄÚÈݵÄȨÏÞ¹ý·ÖÊÚÓ裬ʹµÃÿ¸öÈ˾ùÄܼòµ¥µØÌæ´ú¶ÔÓ¦ÓÚÄÇЩÊý¾Ý¿â±íµÄÎļþ£¬ÄÇôȷ±£¿ØÖÆ¿Í»§Í¨¹ýÍøÂç·ÃÎʵÄÊÚȨ±íÉèÖÃÕýÈ·£¬¶Ô´ËºÁÎÞÒâÒå¡£

Íⲿ°²È«ÐÔ¹ØÐĵÄÊÇ´ÓÍⲿͨ¹ýÍøÂçÁ¬½Ó·þÎñÆ÷µÄ¿Í»§µÄÎÊÌ⣬¼´£¬±£»¤MySQL·þÎñÆ÷ÃâÊÜÀ´×Ôͨ¹ýÍøÂç¶Ô·þÎñÆ÷µÄÁ¬½ÓµÄ¹¥»÷¡£Äã±ØÐëÉèÖÃMySQLÊÚȨ±í£¨grant table£©£¬Ê¹µÃËûÃDz»ÔÊÐí·ÃÎÊ·þÎñÆ÷¹ÜÀíµÄÊý¾Ý¿âÄÚÈÝ£¬³ý·ÇÌṩÓÐЧµÄÓû§ÃûºÍ¿ÚÁî¡£

ÏÂÃæ¾ÍÏêϸ½éÉÜÈçºÎÉèÖÃÎļþϵͳºÍÊÚȨ±ímysql£¬ÊµÏÖMySQLµÄÁ½¼¶°²È«ÐÔ¡£

Ò»¡¢ÄÚ²¿°²È«ÐÔ-±£Ö¤Êý¾ÝĿ¼·ÃÎʵݲȫ

MySQL·þÎñÆ÷ͨ¹ýÔÚMySQLÊý¾Ý¿âÖеÄÊÚȨ±íÌṩÁËÒ»¸öÁé»îµÄȨÏÞϵͳ¡£Äã¿ÉÒÔÉèÖÃÕâЩ±íµÄÄÚÈÝ£¬ÔÊÐí»ò¾Ü¾ø¿Í»§¶ÔÊý¾Ý¿âµÄ·ÃÎÊ£¬ÕâÌṩÁËÄã·ÀֹδÊÚȨµÄÍøÂç·ÃÎʶÔÄãÊý¾Ý¿â¹¥»÷µÄ°²È«ÊֶΣ¬È»¶øÈç¹ûÖ÷»úÉÏÆäËûÓû§ÄÜÖ±½Ó·ÃÎÊÊý¾ÝĿ¼ÄÚÈÝ£¬½¨Á¢¶Ôͨ¹ýÍøÂç·ÃÎÊÊý¾Ý¿âµÄÁ¼ºÃ°²È«ÐÔ¶ÔÄãºÁÎÞ°ïÖú£¬³ý·ÇÄãÖªµÀÄãÊǵǼMySQL·þÎñÆ÷ÔËÐÐÖ÷»úµÄΨһÓû§£¬·ñÔòÄãÐèÒª¹ØÐÄÔÚÕą̂»úÆ÷ÉϵÄÆäËûÓû§»ñµÃ¶ÔÊý¾ÝĿ¼µÄ·ÃÎʵĿÉÄÜÐÔ¡£

ÒÔÏÂÊÇÄãÓ¦¸Ã±£»¤µÄÄÚÈÝ£º

Êý¾Ý¿âÎļþ¡£ºÜÃ÷ÏÔ£¬ÄãҪά»¤·þÎñÆ÷¹ÜÀíµÄÊý¾Ý¿âµÄ˽ÓÃÐÔ¡£Êý¾Ý¿âÓµÓÐÕßͨ³£²¢ÇÒÓ¦¸Ã¿¼ÂÇÊý¾Ý¿âÄÚÈݵݲȫÐÔ£¬¼´Ê¹ËûÃDz»Ï룬ҲӦ¸Ã¿¼ÂÇʱÊý¾Ý¿âÄÚÈݹ«¿ª»¯£¬¶ø²»ÊÇͨ¹ýÔã¸âµÄÊý¾ÝĿ¼µÄ°²È«ÐÔÀ´±©Â¶ÕâЩÄÚÈÝ¡£

ÈÕÖ¾Îļþ¡£Ò»°ãºÍ¸üÐÂÈÕÖ¾±ØÐë±£Ö¤°²È«£¬ÒòΪËûÃÇ°üº¬²éѯÎı¾¡£¶ÔÈÕÖ¾ÎļþÓзÃÎÊȨÏÞµÄÈκÎÈË¿ÉÒÔ¼àÊÓÊý¾Ý¿â½øÐйýµÄ²Ù×÷¡£

¸üÒªÖص㿼ÂǵÄÈÕÖ¾Îļþ°²È«ÐÔÊÇÖîÈçGRANTºÍSET PASSWORDµÈµÄ²éѯҲ±»¼ÇÔØÁË£¬Ò»°ãºÍ¸üÐÂÈÕÖ¾°üº¬ÓÐÃô¸Ð²éѯµÄÎı¾£¬°üÀ¨¿ÚÁMySQLʹÓÿÚÁî¼ÓÃÜ£¬µ«ËüÔÚÒѾ­Íê³ÉÉèÖúó²ÅÔËÓÃÓÚÒÔºóµÄÁ¬½Ó½¨Á¢¡£ÉèÖÃÒ»¸ö¿ÚÁîµÄ¹ý³ÌÉè¼ÆÏóGRANT»òSET PASSWORDµÈ²éѯ£¬²¢ÇÒÕâЩ²éѯÒÔÆÕͨÎı¾ÐÎʽ¼ÇÔØÔÚÈÕÖ¾ÎļþÖУ©¡£Èç¹ûÒ»¸ö¹¥»÷ÕßÓÌÈçÈÕÎļþµÄ¶ÁȨÏÞ£¬Ö»ÐèÔÚÈÕÖ¾ÎļþÉÏÔËÐÐgrepÑ°ÕÒÖîÈçGRANTºÍPASSWORDµÈ´ÊÀ´·¢ÏÖÃô¸ÐÐÅÏ¢¡£

ÏÔÈ»£¬Äã²»ÏëÈ÷þÎñÆ÷Ö÷»úÉϵÄÆäËûÓû§ÓÐÊý¾Ý¿âĿ¼ÎļþµÄдȨÏÞ£¬ÒòΪËûÃÇ¿ÉÒÔÖØдÄãµÄ״̬Îļþ»òÊý¾Ý¿â±íÎļþ£¬µ«ÊǶÁȨÏÞÒ²ºÜΣÏÕ¡£Èç¹ûÒ»¸öÊý¾Ý¿â±íÎļþÄܱ»¶ÁÈ¡£¬ÍµÈ¡Îļþ²¢µÃµ½MySQL±¾Éí£¬ÒÔÆÕͨÎı¾ÏÔʾ±íµÄÄÚÈÝÒ²ºÜÂé·³£¬ÎªÊ²Ã´£¿ÒòΪÄãÒª×öÏÂÁÐÊÂÇ飺

ÔÚ·þÎñÆ÷Ö÷»úÉÏ°²×°Äã×Ô¼º¡°ÌØÖÆ¡±µÄMySQL·þÎñÆ÷£¬µ«ÊÇÓÐÒ»¸ö²»Í¬ÓÚ¹Ù·½·þÎñÆ÷°æ±¾µÄ¶Ë¿Ú¡¢Ì×½Ó×ÖºÍÊý¾ÝĿ¼¡£

ÔËÐÐmysql_install_db³õʼ»¯ÄãµÄÊý¾ÝĿ¼£¬Õ⸳ÓèÄã×÷ΪMySQL rootÓû§·ÃÎÊÄãµÄ·þÎñÆ÷µÄȨÏÞ£¬ËùÒÔÄãÓжԷþÎñÆ÷·ÃÎÊ»úÖƵÄÍêÈ«¿ØÖÆ£¬ËüÒ²½¨Á¢Ò»¸ötestÊý¾Ý¿â¡£

½«¶ÔÓ¦ÓÚÄãÏë͵ȡµÃ±íÎļþ¿½±´µ½Äã·þÎñÆ÷µÄÊý¾Ý¿âĿ¼ÏµÄtestĿ¼¡£

Æô¶¯ÄãµÄ·þÎñÆ÷¡£Äã¿ÉÒÔËæÒâ·ÃÎÊÊý¾Ý¿â±í£¬SHOW TABLES FROM testÏÔʾÄãÓÐÒ»¸ö͵À´µÄ±íµÄ¿½±´£¬SELECT *ÏÔʾËüÃÇÈκÎÒ»¸öµÄÈ«²¿ÄÚÈÝ¡£

Èç¹ûÄãȷʵºÜ¶ñ¶¾£¬½«È¨ÏÞ¹«¿ª¸øÄã·þÎñÆ÷µÄÈκÎÄäÃûÓû§£¬ÕâÑùÈκÎÈËÄÜ´ÓÈκεط½Á¬½Ó·þÎñÆ÷·ÃÎÊÄãµÄtestÊý¾Ý¿â¡£ÄãÏÖÔÚ½«ÍµÀ´µÄÊý¾Ý¿â±í¹«²¼ÓÚÖÚÁË¡£

ÔÚ¿¼ÂÇһϣ¬´ÓÏà·´µÄ½Ç¶È£¬ÄãÏëÈñðÈ˶ÔÄãÕâÑùÂ𣿵±È»²»£¡Äã¿ÉÒÔͨ¹ýÔÚÊý¾Ý¿â¼ÏÂÖ´ÐÐls -lÃüÁîÈ·¶¨ÄãµÄÊý¾Ý¿âÊÇ·ñ°üº¬²»°²È«µÄÎļþºÍĿ¼¡£²éÕÒÓС°×顱ºÍ¡°ÆäËûÓû§¡±È¨ÏÞÉèÖõÄÎļþºÍĿ¼¡£ÏÂÃæÊÇÒ»¸ö²»°²È«Êý¾ÝĿ¼µÄÒ»²¿·ÖÁгö£º

¡¡

% ls -l

total 10148

drwxrwxr-x 11 mysqladm wheel  1024 May 8 12:20 .

drwxr-xr-x 22 root   wheel   512 May 8 13:31 ..

drwx------  2 mysqladm mysqlgrp 512 Apr 16 15:57 menagerie

drwxrwxr-x  2 mysqladm wheel   512 Jan 25 20:40 mysql

drwxrwxr-x  7 mysqladm wheel   512 Aug 31 1998 sql-bench

drwxrwxr-x  2 mysqladm wheel  1536 May 6 06:11 test

drwx------  2 mysqladm mysqlgrp 1024 May 8 18:43 tmp

....

ÕýÈçÄã¿´µ½µÄ£¬ÓÐЩÊý¾Ý¿âÓÐÕýÈ·µÄȨÏÞ£¬¶øÆäËû²»ÊÇ¡£±¾ÀýµÄÇéÐÎÊǾ­¹ýÒ»¶Îʱ¼äºóµÄ½á¹û¡£½ÏÉÙÏÞÖƵÄȨÏÞÓÉÔÚȨÏÞÉèÖ÷½Ãæ±È¸üа汾¸ü²»ÑϸñµÄ½ÏÔç°æ±¾·þÎñÆ÷ÉèÖõģ¨×¢Òâ¸ü¾ßÏÞÖƵÄĿ¼menageriaºÍtmp¶¼ÓнϽüÈÕÆÚ£©¡£MySQLµ±Ç°°æ±¾È·±£ÕâЩÎļþÖ»ÄÜÓÉÔËÐзþÎñÆ÷µÄÓû§¶ÁÈ¡¡£

ÈÃÎÒÃÇÀ´ÐÞÕýÕâЩȨÏÞ£¬Ê¹µÃÖ»Ó÷þÎñÆ÷Óû§¿É·ÃÎÊËüÃÇ¡£ÄãµÄÖ÷Òª±£»¤¹¤¾ßÀ´×ÔÓÚÓÉUNIXÎļþϵͳ±¾ÉíÌṩµÄÉèÖÃÎļþºÍĿ¼ÊôÖ÷ºÍģʽµÄ¹¤¾ß¡£ÏÂÃæÊÇÎÒÃÇÒª×öµÄ£º

½øÈë¸ÃĿ¼

% cd DATADIR

ÉèÖÃËùÓÐÔÚÊý¾ÝĿ¼ÏµÄÎļþÊôÖ÷ΪÓÉÓÃÓÚÔËÐзþÎñÆ÷µÄÕ˺ÅÓµÓУ¨Äã±ØÐëÒÔrootÖ´ÐÐÕâ²½£©¡£ÔÚ±¾ÎÄʹÓÃmysqladmºÍmysqlgrp×÷Ϊ¸ÃÕ˺ŵÄÓû§ÃûºÍ×éÃû¡£Äã¿ÉÒÔʹÓÃÏÂÁÐÃüÁîÖ®Ò»¸Ä±äÊôÖ÷£º

# chown mysqladm.mysqlgrp .

# find . -follow -type d -print | xargs chown mysqladm.mysqlgrp

ÉèÖÃÄãµÄÊý¾ÝĿ¼ºÍÊý¾Ý¿âĿ¼µÄģʽʹµÃËûÃÇÖ»ÄÜÓÉmysqladm¶ÁÈ¡£¬Õâ×èÖ¹ÆäËûÓû§·ÃÎÊÄãÊý¾Ý¿âĿ¼µÄÄÚÈÝ¡£Äã¿ÉÒÔÓÃÏÂÁÐÃüÁîÖ®Ò»ÒÔroot»òmysqladmÉí·ÝÔËÐС£

% chmod -R go-rwx .

% find . -follow -type d -print | xargs chmod go-rwx

Êý¾ÝĿ¼ÄÚÈݵÄÊôÖ÷ºÍģʽΪmysqladmÉèÖá£ÏÖÔÚÄãÓ¦¸Ã±£Ö¤Äã×ÜÊÇÒÔmysqladmÓû§ÔËÐзþÎñÆ÷£¬ÒòΪÏÖÔÚÕâÊÇΨһÓÉ·ÃÎÊÊý¾Ý¿âĿ¼ȨÏÞµÄÓû§£¨³ýroot£©¡£

ÔÚÍê³ÉÕâЩÉèÖúó£¬Äã×îÖÕÓ¦¸ÃµÃµ½ÏÂÃæµÄÊý¾ÝĿ¼ȨÏÞ£º

% ls -l

total 10148

drwxrwx--- 11 mysqladm mysqlgrp 1024 May 8 12:20 .

drwxr-xr-x 22 root   wheel   512 May 8 13:31 ..

drwx------  2 mysqladm mysqlgrp 512 Apr 16 15:57 menagerie

drwx------  2 mysqladm mysqlgrp 512 Jan 25 20:40 mysql

drwx------  7 mysqladm mysqlgrp 512 Aug 31 1998 sql-bench

drwx------  2 mysqladm mysqlgrp 1536 May 6 06:11 test

drwx------  2 mysqladm mysqlgrp 1024 May 8 18:43 tmp

....

¶þ¡¢Íⲿ°²È«ÐÔ-±£Ö¤ÍøÂç·ÃÎʵݲȫ

MySQLµÄ°²È«ÏµÍ³ÊǺÜÁé»îµÄ£¬ËüÔÊÐíÄãÒÔ¶àÖÖ²»Í¬·½Ê½ÉèÖÃÓû§È¨ÏÞ¡£Ò»°ãµØ£¬Äã¿ÉʹÓñê×¼µÄSQLÓï¾äGRANTºÍREVOKEÓï¾ä×ö£¬ËûÃÇΪÄãÐ޸ĿØÖÆ¿Í»§·ÃÎʵÄÊÚȨ±í£¬È»¶ø£¬Äã¿ÉÄÜÓÉÒ»¸ö²»Ö§³ÖÕâЩÓï¾äµÄÀÏ°æ±¾µÄMySQL£¨ÔÚ3.22.11֮ǰÕâЩÓï¾ä²»Æð×÷Óã©£¬»òÕßÄã·¢¾õÓû§È¨ÏÞ¿´ÆðÀ´²»ÊÇÒÔÄãÏëÒªµÄ·½Ê½¹¤×÷¡£¶ÔÓÚÕâÖÖÇé¿ö£¬Á˽âMySQLÊÚȨ±íµÄ½á¹¹ºÍ·þÎñÆ÷ÈçºÎÀûÓÃËüÃǾö¶¨·ÃÎÊȨÏÞÊÇÓаïÖúµÄ£¬ÕâÑùµÄÁ˽âÔÊÐíÄãͨ¹ýÖ±½ÓÐÞ¸ÄÊÚȨ±íÔö¼Ó¡¢É¾³ý»òÐÞ¸ÄÓû§È¨ÏÞ£¬ËüÒ²ÔÊÐíÄãÔÚ¼ì²éÕâЩ±íʱÕï¶ÏȨÏÞÎÊÌâ¡£

¹ØÓÚÈçºÎ¹ÜÀíÓû§Õ˺ţ¬¼û¡¶MySQLµÄÓû§¹ÜÀí¡·¡£¶ø¶ÔGRANTºÍREVOKEÓï¾äÏêϸÃèÊö£¬¼û¡¶MySQL²Î¿¼Êֲᡷ¡£

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

ͨ¹ýÍøÂçÁ¬½Ó·þÎñÆ÷µÄ¿Í»§¶ÔMySQLÊý¾Ý¿âµÄ·ÃÎÊÓÉÊÚȨ±íÄÚÈÝÀ´¿ØÖÆ¡£ÕâЩ±íλÓÚmysqlÊý¾Ý¿âÖУ¬²¢ÔÚµÚÒ»´Î°²×°MySQLµÄ¹ý³ÌÖгõʼ»¯£¨ÔËÐÐmysql_install_db½Å±¾£©¡£ÊÚȨ±í¹²ÓÐ5¸ö±í£ºuser¡¢db¡¢host¡¢tables_privºÍcolumns_priv¡£

±í1 user¡¢dbºÍhostÊÚȨ±í½á¹¹

·ÃÎÊ·¶Î§ÁÐ

user db host

Host Host Host

User Db Db

Password User 

Êý¾Ý¿â/±íȨÏÞÁÐ

Alter_priv Alter_priv Alter_priv

Create_priv Create_priv Create_priv

Delete_priv Delete_priv Delete_priv

Drop_priv Drop_priv Drop_priv

Index_priv Index_priv Index_priv

Insert_priv Insert_priv Insert_priv

References_priv References_priv References_priv

Select_priv Select_priv Select_priv

Update_priv Update_priv Update_priv

File_priv Grant_priv Grant_priv

Grant_priv 

Process_priv 

Reload_priv 

Shutdown_priv 

¡¡

±í2 tables_privºÍcolumns_privÊôȨ±í½á¹¹

·ÃÎÊ·¶Î§ÁÐ

tables_priv columns_priv

Host Host

Db Db

User User

Table_name Table_name

Column_name 

ȨÏÞÁÐ

Table_priv Column_priv

ÊÚȨ±íµÄÄÚÈÝÓÐÈçÏÂÓÃ;£º

user±í

user±íÁгö¿ÉÒÔÁ¬½Ó·þÎñÆ÷µÄÓû§¼°Æä¿ÚÁ²¢ÇÒËüÖ¸¶¨ËûÃÇÓÐÄÄÖÖÈ«¾Ö£¨³¬¼¶Óû§£©È¨ÏÞ¡£ÔÚuser±íÆôÓõÄÈκÎȨÏÞ¾ùÊÇÈ«¾ÖȨÏÞ£¬²¢ÊÊÓÃÓÚËùÓÐÊý¾Ý¿â¡£ÀýÈ磬Èç¹ûÄãÆôÓÃÁËDELETEȨÏÞ£¬ÔÚÕâÀïÁгöµÄÓû§¿ÉÒÔ´ÓÈκαíÖÐɾ³ý¼Ç¼£¬ËùÒÔÔÚÄãÕâÑù×ö֮ǰҪÈÏÕ濼ÂÇ¡£

db±í

db±íÁгöÊý¾Ý¿â£¬¶øÓû§ÓÐȨÏÞ·ÃÎÊËüÃÇ¡£ÔÚÕâÀïÖ¸¶¨µÄȨÏÞÊÊÓÃÓÚÒ»¸öÊý¾Ý¿âÖеÄËùÓÐ±í¡£

host±í

host±íÓëdb±í½áºÏʹÓÃÔÚÒ»¸ö½ÏºÃ²ã´ÎÉÏ¿ØÖÆÌض¨Ö÷»ú¶ÔÊý¾Ý¿âµÄ·ÃÎÊȨÏÞ£¬Õâ¿ÉÄܱȵ¥¶ÀʹÓÃdbºÃЩ¡£Õâ¸ö±í²»ÊÜGRANTºÍREVOKEÓï¾äµÄÓ°Ï죬ËùÒÔ£¬Äã¿ÉÄÜ·¢¾õÄã¸ù±¾²»ÊÇÓÃËü¡£

tables_priv±í

tables_priv±íÖ¸¶¨±í¼¶È¨ÏÞ£¬ÔÚÕâÀïÖ¸¶¨µÄÒ»¸öȨÏÞÊÊÓÃÓÚÒ»¸ö±íµÄËùÓÐÁС£

columns_priv±í

columns_priv±íÖ¸¶¨Áм¶È¨ÏÞ¡£ÕâÀïÖ¸¶¨µÄȨÏÞÊÊÓÃÓÚÒ»¸ö±íµÄÌض¨ÁС£

ÔÚ¡°²»ÓÃGRANTÉèÖÃÓû§¡±Ò»½ÚÀÎÒÃÇÔÙÌÖÂÛGRANTÓï¾äÈçºÎ¶ÔÐÞ¸ÄÕâЩ±íÆð×÷Ó㬺ÍÄãÔõÑùÄÜͨ¹ýÖ±½ÓÐÞ¸ÄÊÚȨ±í´ïµ½Í¬ÑùµÄЧ¹û¡£

tables_privºÍcolumns_priv±íÔÚMySQL 3.22.11°æÒý½ø£¨ÓëGRANTÓï¾äͬʱ£©¡£Èç¹ûÄãÓнÏÔç°æ±¾µÄMySQL£¬ÄãµÄmysqlÊý¾Ý¿â½«Ö»ÓÐuser¡¢dbºÍhost±í¡£Èç¹ûÄã´ÓÀÏ°æ±¾Éý¼¶µ½3.22.11»ò¸üУ¬¶øûÓÐtables_privºÍcolumns_priv±í£¬ÔËÐÐmysql_fix_privileges_tables½Å±¾´´½¨ËüÃÇ¡£

MySQLûÓÐrows_priv±í£¬ÒòΪËü²»Ìṩ¼Ç¼¼¶È¨ÏÞ£¬ÀýÈ磬Äã²»ÄÜÏÞÖÆÓû§ÓÚ±íÖаüº¬Ìض¨ÁÐÖµµÄÐС£Èç¹ûÄãȷʵÐèÒªÕâÖÖÄÜÁ¦£¬Äã±ØÐëÓÃÓ¦Óñà³ÌÀ´Ìṩ¡£Èç¹ûÄãÏëÖ´Ðн¨ÒéµÄ¼Ç¼¼¶Ëø¶¨£¬Äã¿ÉÓÃGET_LOCK()º¯Êý×öµ½¡£

ÊÚȨ±í°üº¬Á½ÖÖÁУº¾ö¶¨Ò»¸öȨÏÞºÎʱÔËÓõķ¶Î§Áк;ö¶¨ÊÚÓèÄÄÖÖȨÏÞµÄȨÏÞÁС£

2.1.1 ÊÚȨ±í·¶Î§ÁÐ

ÊÚȨ±í·¶Î§ÁÐÖ¸¶¨±íÖеÄȨÏÞºÎʱÔËÓá£Ã¿¸öÊÚȨ±íÌõÄ¿°üº¬UserºÍHostÁÐÀ´Ö¸¶¨È¨ÏÞºÎʱÔËÓÃÓÚÒ»¸ö¸ø¶¨Óû§´Ó¸ø¶¨Ö÷»úµÄÁ¬½Ó¡£ÆäËû±í°üº¬¸½¼ÓµÄ·¶Î§ÁУ¬Èçdb±í°üº¬Ò»¸öDbÁÐÖ¸³öȨÏÞÔËÓÃÓÚÄĸöÊý¾Ý¿â¡£ÀàËƵأ¬tables_privºÍcolumns_priv±í°üº¬·¶Î§×ֶΣ¬ËõС·¶Î§µ½Ò»¸öÊý¾Ý¿âÖеÄÌض¨±í»òÒ»¸ö±íµÄÌض¨ÁС£

2.1.2 ÊÚȨ±íȨÏÞÁÐ

ÊÚȨ±í»¹°üº¬È¨ÏÞÁУ¬ËûÃÇÖ¸³öÔÚ·¶Î§ÁÐÖÐÖ¸¶¨µÄÓû§ÓµÓкÎÖÖȨÏÞ¡£ÓÉMySQLÖ§³ÖµÄȨÏÞÈçϱíËùʾ¡£¸Ã±íʹÓÃGRANTÓï¾äµÄȨÏÞÃû³Æ¡£¶ÔÓÚ¾ø´ó¶àÊýÔÚuser¡¢dbºÍhost±íÖеÄȨÏÞÁеÄÃû³ÆÓëGRANTÓï¾äÖÐÓÐÃ÷ÏÔµÄÁªÏµ¡£ÈçSelect_priv¶ÔÓ¦ÓÚSELECTȨÏÞ¡£

2.1.3 Êý¾Ý¿âºÍ±íȨÏÞ

ÏÂÁÐȨÏÞÔËÓÃÓÚÊý¾Ý¿âºÍ±íÉϵIJÙ×÷¡£

ALTER

ÔÊÐíÄãʹÓÃALTER TABLEÓï¾ä£¬ÕâÆäʵÊÇÒ»¸ö¼òµ¥µÄµÚÒ»¼¶È¨ÏÞ£¬Äã±ØÐëÓÉÆäËûȨÏÞ£¬Õâ¿´ÄãÏë¶ÔÊý¾Ý¿âʵʩʲô²Ù×÷¡£

CREATE

ÔÊÐíÄã´´½¨Êý¾Ý¿âºÍ±í£¬µ«²»ÔÊÐí´´½¨Ë÷Òý¡£

DELETE

ÔÊÐíÄã´Ó±íÖÐɾ³ýÏÖÓмǼ¡£

DROP

ÔÊÐíÄãɾ³ý£¨Å×Æú£©Êý¾Ý¿âºÍ±í£¬µ«²»ÔÊÐíɾ³ýË÷Òý¡£

INDEX

ÔÊÐíÄã´´½¨²¢É¾³ýË÷Òý¡£

REFERENCES

Ä¿Ç°²»Óá£

SELECT

ÔÊÐíÄãʹÓÃSELECTÓï¾ä´Ó±íÖмìË÷Êý¾Ý¡£¶Ô²»Éæ¼°±íµÄSELECTÓï¾ä¾Í²»±ØÒª£¬ÈçSELECT NOW()»òSELECT 4/2¡£

UPDATE

ÔÊÐíÄãÐ޸ıíÖеÄÒÑÓеļǼ¡£

2.1.4 ¹ÜÀíȨÏÞ

ÏÂÁÐȨÏÞÔËÓÃÓÚ¿ØÖÆ·þÎñÆ÷»òÓû§ÊÚȨÄÜÁ¦µÄ²Ù×÷µÄ¹ÜÀíÐÔ²Ù×÷¡£

FILE

ÔÊÐíÄã¸æËß·þÎñÆ÷¶Á»òд·þÎñÆ÷Ö÷»úÉϵÄÎļþ¡£¸ÃȨÏÞ²»Ó¦¸ÃËæ±ãÊÚÓ裬ËüºÜΣÏÕ£¬¼û¡°»Ø±ÜÊÚȨ±í·çÏÕ¡±¡£·þÎñÆ÷ȷʵ½Ï½÷É÷µØ±£³ÖÔÚÒ»¶¨·¶Î§ÄÚʹÓøÃȨÏÞ¡£ÄãÖ»ÄܶÁÈκÎÈ˶¼ÄܶÁµÄÎļþ¡£ÄãÕýÔÚдµÄÎļþ±ØÐë²»ÊÇÏÖ´æµÄÎļþ£¬Õâ·ÀÖ¹ÄãÆÈʹ·þÎñÆ÷ÖØдÖØÒªÎļþ£¬Èç/etc/passwd»òÊôÓÚ±ðÈ˵ÄÊý¾Ý¿âµÄÊý¾ÝĿ¼¡£

Èç¹ûÄãÊÚȨFILEȨÏÞ£¬È·±£Äã²»ÒÔUNIXµÄrootÓû§ÔËÐзþÎñÆ÷£¬ÒòΪroot¿ÉÔÚÎļþϵͳµÄÈκεط½´´½¨ÐÂÎļþ¡£Èç¹ûÄãÒÔÒ»¸ö·ÇÌØȨÓû§ÔËÐзþÎñÆ÷£¬·þÎñÆ÷Ö»ÄÜÔÚ¸øÓû§ÄÜ·ÃÎʵÄĿ¼Öд´½¨Îļþ¡£

GRANT

ÔÊÐíÄ㽫Äã×Ô¼ºµÄȨÏÞÊÚÓè±ðÈË£¬°üÀ¨GRANT¡£

PROCESS

ÔÊÐíÄãͨ¹ýʹÓÃSHOW PROCESSÓï¾ä»òmysqladmin processÃüÁî²é¿´·þÎñÆ÷ÄÚÕýÔÚÔËÐеÄỊ̈߳¨½ø³Ì£©µÄÐÅÏ¢¡£Õâ¸öȨÏÞÒ²ÔÊÐíÄãÓÃKILLÓï¾ä»òmysqladmin killÃüÁîɱËÀÏ̡߳£

Äã×ÜÊÇÄÜ¿´µ½»òɱËÀÄã×Ô¼ºµÄÏ̡߳£PROCESSȨÏÞ¸³ÓèÄã¶ÔÈκÎÏß³Ì×öÕâЩÊÂÇéµÄÄÜÁ¦¡£

RELOAD

ÔÊÐíÄãÖ´ÐдóÁ¿µÄ·þÎñÆ÷¹ÜÀí²Ù×÷¡£Äã¿ÉÒÔ·¢³öFLUSHÓï¾ä£¬ÄãÒ²ÄÜÖ¸ÐÔmysqladminµÄreload¡¢refresh¡¢flush-hosts¡¢flush-logs¡¢flush-privilegesºÍflush-tablesµÈÃüÁî¡£

SHUTDOWN

ÔÊÐíÄãÓÃmysqladmin shutdown¹Ø±Õ·þÎñÆ÷¡£

ÔÚuser¡¢dbºÍhost±íÖУ¬Ã¿Ò»¸öȨÏÞÒÔÒ»¸öµ¥¶ÀµÄÁÐÖ¸¶¨¡£ÕâЩÁÐÈ«²¿ÉùÃ÷Ϊһ¸öENUM("N","Y")ÀàÐÍ£¬ËùÒÔÿ¸öȨµÄȱʡֵÊÇ¡°N¡±¡£ÔÚtables_privºÍcolumns_privÖеÄȨÏÞÒÔÒ»¸öSET±íʾ£¬ËüÔÊÐíȨÏÞÓÃÒ»¸öµ¥¸öÁÐÒÔÈκÎ×éºÏÖ¸¶¨¡£ÕâÁ½¸ö±í±ÈÆäËûÈý¸ö±í¸üУ¬Õâ¾ÍÊÇΪʲôËüÃÇʹÓøüÓÐЧµÄ±íʾ·½Ê½µÄÔ­Òò¡££¨ÓпÉÄÜÔÚδÀ´£¬user¡¢dbºÍhost±íÒ²ÓÃÒ»¸öSETÀàÐͱíʾ¡££©

ÔÚtables_priv±íÖеÄTable_privÁỶ¨Òå³É£º

SET('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter')

ÔÚcoloums_priv±íÖеÄColumn_privÁỶ¨Òå³É£º¡¡

SET('Select','Insert','Update','References')

ÁÐȨÏޱȱíȨÏÞÉÙ£¬ÒòΪÁм¶½ÏÉÙµÄȨÏÞÓÐÒâÒå¡£ÀýÈçÄãÄÜ´´½¨Ò»¸ö±í£¬µ«Äã²»ÄÜ´´½¨Ò»¸ö¹ÂÁ¢µÄÁС£

user±í°üº¬Ä³Ð©ÔÚÆäËûÊÚȨ±í²»´æÔÚµÄȨÏÞµÄÁУºFile_priv¡¢Process_priv¡¢Reload_privºÍShutdown_priv¡£ÕâЩȨÏÞÔËÓÃÓÚÄãÈ÷þÎñÆ÷Ö´ÐеÄÓëÈκÎÌض¨Êý¾Ý¿â»ò±í²»Ïà¹ØµÄ²Ù×÷¡£ÈçÔÊÐíÒ»¸öÓû§¸ù¾Ýµ±Ç°Êý¾Ý¿âÊÇʲôÀ´¹Ø±ÕÊý¾Ý¿âÊǺÁÎÞÒâÒåµÄ¡£

2.2 ·þÎñÆ÷ÈçºÎ¿ØÖÆ¿Í»§·ÃÎÊ

ÔÚÄãʹÓÃMySQLʱ£¬¿Í»§·ÃÎÊ¿ØÖÆÓÐÁ½¸ö½×¶Î¡£µÚÒ»½×¶Î·¢ÉúÔÚÄãÊÔͼÁ¬½Ó·þÎñÆ÷ʱ¡£·þÎñÆ÷²éÕÒuser±í¿´ËüÊÇ·ñÄÜÕÒµ½Ò»¸öÌõÄ¿Æ¥ÅäÄãµÄÃû×Ö¡¢ÄãÕýÔÚ´ÓÄǶùÁ¬½ÓµÄÖ÷»úºÍÄãÌṩµÄ¿ÚÁî¡£Èç¹ûûÓÐÆ¥Å䣬Äã¾Í²»ÄÜÁ¬½Ó¡£Èç¹ûÓÐÒ»¸öÆ¥Å䣬½¨Á¢Á¬½Ó²¢¼ÌÐøµÚ¶þ½×¶Î¡£ÔÚÕâ¸ö½×¶Î£¬¶ÔÓÚÿһ¸öÄã·¢³öµÄ²éѯ£¬·þÎñÆ÷¼ì²éÊÚȨ±í¿´ÄãÊÇ·ñÓÐ×ã¹»µÄȨÏÞÖ´Ðвéѯ£¬µÚ¶þ½×¶Î³ÖÐøµ½ÄãÓë·þÎñÆ÷¶Ô»°µÄ½áÊø¡£

±¾Ð¡½ÚÏêϸ½éÉÜMySQL·þÎñÆ÷ÓÃÓÚ½«ÊÚȨ±íÌõÄ¿Æ¥Åäµ½À´µÄÁ¬½ÓÇëÇó»ò²éѯµÄÔ­Ôò£¬Õâ°üÀ¨ÔÚÊÚȨ±í·¶Î§ÁÐÖкϷ¨µÄÖµµÄÀàÐÍ¡¢½áºÏÊÚȨ±íÖеÄȨÏÞÐÅÏ¢µÄ·½Ê½ºÍ±íÖÐÌõÄ¿±»¼ì²éµÄ´ÎÐò¡£

2.2.1 ·¶Î§ÁÐÄÚÈÝ

һЩ·¶Î§ÁÐÒªÇóÎÄ×ÖÖµ£¬µ«ËüÃÇ´ó¶àÊýÔÊÐíͨÅä·û»òÆäËûÌØÊâÖµ¡£

Host

Ò»¸öHostÁÐÖµ¿ÉÒÔÊÇÒ»¸öÖ÷»úÃû»òÒ»¸öIPµØÖ·¡£ÖµlocalhostÒâζ×ű¾µØÖ÷»ú£¬µ«ËüÖ»ÔÚÄãÓÃÒ»¸ölocalhostÖ÷»úÃûʱ²ÅÆ¥Å䣬¶ø²»ÊÇÄãÔÚʹÓÃÖ÷»úÃûʱ¡£¼ÙÈçÄãµÄ±¾µØÖ÷»úÃûÊÇpit.snake.net²¢ÇÒÔÚuser±íÖÐÓжÔÄãµÄÁ½Ìõ¼Ç¼£¬Ò»¸öÓÐÒ»¸öHostÖµ»òlocalhost£¬¶øÁíÒ»¸öÓÐpit.snake.net£¬ÓÐlocalhostµÄ¼Ç¼½«Ö»µ±ÄãÁ¬½ÓlocalhostʱƥÅ䣬ÆäËûÔÚÖ»ÔÚÁ¬½Ópit.snake.netʱ²ÅÆ¥Åä¡£Èç¹ûÄãÏëÈÿͻ§ÄÜÒÔÁ½ÖÖ·½Ê½Á¬½Ó£¬ÄãÐèÒªÔÚuser±íÖÐÓÐÁ½Ìõ¼Ç¼¡£

ÄãÒ²¿ÉÒÔÓÃͨÅä·ûÖ¸¶¨HostÖµ¡£¿ÉÒÔʹÓÃSQLµÄģʽ×Ö·û¡°%¡±ºÍ¡°_¡±²¢¾ßÓе±ÄãÔÚÒ»¸ö²éѯÖÐʹÓÃLIKEËã·ûͬÑùµÄº¬Ò壨²»ÔÊÐíregexËã·û£©¡£ SQLģʽ×Ö·û¶¼ÄÜÓÃÓÚÖ÷»úÃûºÍIPµØÖ·¡£Èç%wisc.eduÆ¥ÅäÈκÎwisc.eduÓòÄÚµÄÖ÷»ú£¬¶ø%.eduÆ¥ÅäÈκνÌÓýѧԺµÄÖ÷»ú¡£ÀàËƵأ¬192.168.%Æ¥ÅäÈκÎÔÚ192.168 BÀà×ÓÍøµÄÖ÷»ú£¬¶ø192.168.3.%Æ¥ÅäÈκÎÔÚ192.168.3 CÀà×ÓÍøµÄÖ÷»ú¡£

%ֵƥÅäËùÓÐÖ÷»ú£¬²¢¿ÉÓÃÓÚÔÊÐíÒ»¸öÓû§´ÓÈκεط½Á¬½Ó¡£Ò»¸ö¿Õ°×µÄHostÖµµÈͬÓÚ%¡££¨ÀýÍ⣺ÔÚdb±íÖУ¬Ò»¸ö¿Õ°×HostÖµº¬ÒåÊÇ¡°½øÒ»²½¼ì²éhost±í¡±£¬¸Ã¹ý³ÌÔÚ¡°²éѯ·ÃÎÊÑéÖ¤¡±ÖнéÉÜ¡££©

´ÓMySQL 3.23Æð£¬ÄãÒ²¿ÉÒÔÖ¸¶¨´øÒ»¸ö±íÃ÷ÄÇЩΪÓÃÓÚÍøÂçµØÖ·µÄÍøÂçÑÚÂëµÄIPµØÖ·£¬Èç192.168.128.0/17Ö¸¶¨Ò»¸ö17λÍøÂçµØÖ·²¢Æ¥ÅäÆäIPµØÖ·ÊÇ192.168.128Ç°17λµÄÈκÎÖ÷»ú¡£

User

Óû§Ãû±ØÐëÊÇÎÄ×ֵĻò¿Õ°×¡£Ò»¸ö¿Õ°×ֵƥÅäÈκÎÓû§¡£%×÷Ϊһ¸öUserÖµ²»Òâζ×Å¿Õ°×£¬Ïà·´ËüÆ¥ÅäÒ»¸ö×ÖÃæÉϵÄ%Ãû×Ö£¬Õâ¿ÉÄܲ»ÊÇÄãÏëÒªµÄ¡£

µ±Ò»¸öµ½À´µÄÁ¬½Óͨ¹ýuser±í±»ÑéÖ¤¶øÆ¥ÅäµÄ¼Ç¼°üº¬Ò»¸ö¿Õ°×µÄUserÖµ£¬¿Í»§±»ÈÏΪÊÇÒ»¸öÄäÃûÓû§¡£

Password

¿ÚÁîÖµ¿ÉÒÔÊÇ¿Õ»ò·Ç¿Õ£¬²»ÔÊÐíÓÃͨÅä·û¡£Ò»¸ö¿Õ¿ÚÁî²»Òâζ×ÅÆ¥ÅäÈκοÚÁËüÒâζ×ÅÓû§±ØÐë²»Ö¸¶¨¿ÚÁî¡£

¿ÚÁîÒÔÒ»¸ö¼ÓÃܹýµÄÖµ´æ´¢£¬²»ÊÇÒ»¸ö×ÖÃæÉϵÄÎı¾¡£Èç¹ûÄãÔÚPasswordÁÐÖд洢һ¸öÕÕ×ÖÃæÉϵĿÚÁÓû§½«²»ÄÜÁ¬½Ó£¡GRANTÓï¾äºÍmysqladmin passwordÃüÁîΪÄã×Ô¶¯¼ÓÃÜ¿ÚÁµ«ÊÇÈç¹ûÄãÓÃÖîÈçINSERT¡¢REPLACE¡¢UPDATE»òSET PASSWORDµÈÃüÁһ¶¨ÒªÓÃPASSWORD("new_password")¶ø²»ÊǼòµ¥µÄ"new_password"À´Ö¸¶¨¿ÚÁî¡£

Db

ÔÚcolumns_privºÍtables_priv±íÖУ¬DbÖµ±ØÐëÊÇÕæÕýµÄÊý¾Ý¿âÃû£¨ÕÕ×ÖÃæÉÏ£©£¬²»ÔÊÐíģʽºÍ¿Õ°×¡£ÔÚdbºÍhostÖУ¬DbÖµ¿ÉÒÔÒÔ×ÖÃæÒâÒåÖ¸¶¨»òʹÓÃSQLģʽ×Ö·û'%'»ò'_'Ö¸¶¨Ò»¸öͨÅä·û¡£Ò»¸ö'%'»ò¿Õ°×Æ¥ÅäÈκÎÊý¾Ý¿â¡£

Table_name£¬Column_name

ÕâЩÁÐÖеÄÖµ±ØÐëÊÇÕÕ×ÖÃæÒâ˼µÄ±í»òÁÐÃû£¬²»ÔÊÐíģʽºÍ¿Õ°×¡£

ijЩ·¶Î§Áб»·þÎñÆ÷ÊÓΪ´óСдÃô¸ÐµÄ£¬ÆäÓ಻ÊÇ¡£ÕâЩԭÔò×ܽáÔÚϱíÖС£Ìرð×¢ÒâTable_nameÖµ×ÜÊDZ»¿´×÷´óСдÃô¸ÐµÄ£¬¼´Ê¹ÔÚ²éѯÖеıíÃûµÄ´óСдÃô¸ÐÐÔ¶Ô´ýÊÓ·þÎñÆ÷ÔËÐеÄÖ÷»úµÄÎļþϵͳ¶ø¶¨£¨UNIXÏÂÊÇ´óСдÃô¸Ð£¬¶øWindows²»ÊÇ£©¡£

±í3 ÊÚȨ±í·¶Î§ÁеĴóСдÃô¸ÐÐÔ

ÁÐ

Host

User

Password

Db

Table_name

Column_name

´óСдÃô¸ÐÐÔ

No

Yes

Yes

Yes

Yes

No

2.2.2 ²éѯ·ÃÎÊÑéÖ¤

ÿ´ÎÄã·¢³öÒ»¸ö²éѯ£¬·þÎñÆ÷¼ì²éÄãÊÇ·ñÓÐ×ã¹»µÄȨÏÞÖ´ÐÐËü£¬ËüÒÔuser¡¢db¡¢tables_privºÍcolumns_privµÄ˳Ðò¼ì²é£¬ÖªµÀËüÈ·¶¨ÄãÓÐÊʵ±µÄ·ÃÎÊȨÏÞ»òÒÑËÑË÷ËùÓбí¶øÒ»ÎÞËù»ñ¡£¸ü¾ßÌåµÄ˵£º

·þÎñÆ÷¼ì²éuser±íÆ¥ÅäÄ㿪ʼÁ¬½ÓµÄ¼Ç¼ÒԲ鿴ÄãÓÐʲôȫ¾ÖȨÏÞ¡£Èç¹ûÄãÓв¢ÇÒËüÃǶԲéѯ×ã¹»ÁË£¬·þÎñÆ÷ÔòÖ´ÐÐËü¡£

Èç¹ûÄãµÄÈ«¾ÖȨÏÞ²»¹»£¬·þÎñÆ÷ΪÄãÔÚdb±íÖÐÑ°ÕÒ²¢½«¸Ã¼Ç¼ÖеÄȨÏÞ¼Óµ½ÄãµÄÈ«¾ÖȨÏÞÖС£Èç¹û½á¹û¶Ô²éѯ×ã¹»£¬·þÎñÆ÷Ö´ÐÐËü¡£

Èç¹ûÄãµÄÈ«¾ÖºÍÊý¾Ý¿â¼¶×éºÏµÄȨÏÞ²»¹»£¬·þÎñÆ÷¼ÌÐø²éÕÒ£¬Ê×ÏÈÔÚtables_priv±í£¬È»ºócolumns_priv±í¡£

Èç¹ûÄãÔÚ¼ì²éÁËËùÓбíÖ®ºóÈÔÎÞȨÏÞ£¬·þÎñÆ÷¾Ü¾øÄãÖ´ÐвéѯµÄÆóͼ¡£

Óò¼¶ûÔËËãµÄÊõÓÊÚȨ±íÖеÄȨÏÞ±»·þÎñÆ÷ÕâÑùʹÓãº

user OR tables_priv OR columns_priv

Äã¿ÉÄÜÒÉ»óΪʲôǰÃæµÄÃèÊöÖ»ÒýÓÃ4¸öÊÚȨ±í£¬¶øʵ¼ÊÉÏÓÐ5¸ö¡£Êµ¼ÊÉÏ·þÎñÆ÷ÊÇÕâÑù¼ì²é·ÃÎÊȨÏÞ£º

user OR (db AND host) OR tables_priv OR columns_priv

µÚÒ»¸ö½Ï¼òµ¥µÄ±í´ïʽÊÇÒòΪhost±í²»ÊÜGRANTºÍREVOKEÓï¾äÓ°Ïì¡£Èç¹ûÄã×ÜÊÇÓÃGRANTºÍREVOKE¹ÜÀíÓû§È¨ÏÞ£¬Äã¾ø²»ÐèÒª¿¼ÂÇhost±í¡£µ«ÊÇÆ乤×÷Ô­ÀíÄãÓøÃÖªµÀ£º

µ±·þÎñÆ÷¼ì²éÊý¾Ý¿â¼¶È¨ÏÞʱ£¬Ëü¶ÔÓÚ¿Í»§²éÕÒdb±í¡£Èç¹ûHostÁÐÊǿյģ¬ËüÒâζ×Å¡°¼ì²éhost±íÒÔÕÒ³öÄÄÒ»¸öÖ÷»úÄÜ·ÃÎÊÊý¾Ý¿â¡±¡£

·þÎñÆ÷ÔÚhost±íÖвéÕÒÓÐÓëÀ´×Ôdb±íµÄ¼Ç¼ÏàͬµÄDbÁÐÖµ¡£Èç¹ûûÓÐhost¼Ç¼ƥÅä¿Í»§Ö÷»ú£¬ÔòûÓÐÊÚÓèÊý¾Ý¿â¼¶È¨ÏÞ¡£Èç¹ûÕâЩ¼Ç¼µÄÈκÎÒ»¸öµÄÈ·ÓÐÒ»¸öÆ¥ÅäÁ¬½ÓµÄ¿Í»§Ö÷»úµÄHostÁÐÖµ£¬db±í¼Ç¼ºÍhost±í¼Ç¼½áºÏ²úÉú¿Í»§µÄÊý¾Ý¿â¼¶È¨ÏÞ¡£

È»¶ø£¬È¨ÏÞÓÃÒ»¸öÂß¼­AND£¨Ó룩½áºÏÆðÀ´£¬ÕâÒâζ×ųý·ÇÒ»¸ö¸ø¶¨µÄȨÏÞÔÚÁ½¸ö±íÖж¼ÓУ¬·ñÔò¿Í»§¾Í²»¾ß±¸¸ÃȨÏÞ¡£ÒÔÕâÖÖ·½Ê½£¬Äã¿ÉÒÔÔÚdb±íÖÐÊÚÓèÒ»¸ö»ù±¾µÄȨÏÞ¼¯£¬È»ºóʹÓÃhost±í¶ÔÌض¨µÄÖ÷»úÓÐÑ¡ÔñµØ½ûÓÃËüÃÇ¡£ÈçÄã¿ÉÒÔÔÊÐí´ÓÄãµÄÓòÖеÄËùÓÐÖ÷»ú·ÃÎÊÊý¾Ý¿â£¬µ«¹Ø±ÕÁËÄÇЩÔڽϲ»°²È«ÇøÓòµÄÖ÷»úµÄÊý¾Ý¿âȨÏÞ¡£

Ç°ÃæµÄÃèÊöºÁÎÞÒÉÎÊʹ·ÃÎʼì²éÌýÆðÀ´Ò»¸öÏ൱¸´ÔӵĹý³Ì£¬ÌرðÊÇÄãÒÔΪ·þÎñÆ÷¶ÔÄã·¢³öµÄÿ¸ö²éѯ½øÐÐȨÏÞ¼ì²é£¬È»¶ø´Ë¹ý³ÌÊǺܿìµÄ£¬ÒòΪ·þÎñÆ÷Æäʵ²»´ÓÊÚȨ±í¶Ôÿ¸ö²éѯ²éÕÒÐÅÏ¢£¬Ïà·´£¬ËüÔÚÆô¶¯Ê±½«±íµÄÄÚÈݶÁÈëÄڴ棬ȻºóÑéÖ¤²éѯÓõÄÊÇÄÚ´æÖеĸ±±¾¡£Õâ´ó´óÌá¸ßÁË·ÃÎʼì²é²Ù×÷µÄÐÔÄÜ¡£µ«ÓÐÒ»¸ö·Ç³£Ã÷ÏԵĸ±×÷Óá£Èç¹ûÄãÖ±½ÓÐÞ¸ÄÊÚȨ±íµÄÄÚÈÝ£¬·þÎñÆ÷½«²»ÖªµÀȨÏ޵ĸı䡣

ÀýÈ磬Èç¹ûÄãÓÃÒ»ÌõINSERTÓï¾äÏòuser±í¼ÓÈëÒ»¸öмǼÀ´Ôö¼ÓÒ»¸öÐÂÓû§£¬ÃüÃûÔڼǼÖеÄÓû§½«²»ÄÜÁ¬½Ó·þÎñÆ÷¡£Õâ¶Ô¹ÜÀíÔ±ÐÂÊÖ£¨ÓÐʱ¶ÔÓо­ÑéµÄÀÏÊÖ£©ÊǺÜÀ§»óµÄÊÂÇ飬µ±Ê±½â¾ö·½·¨ºÜ¼òµ¥£ºÔÚÄã¸Ä±äÁËËüÃÇÖ®ºó¸æËß·þÎñÆ÷ÖØÔØÊÚȨ±íÄÚÈÝ£¬Äã¿ÉÒÔ·¢Ò»ÌõFLUSH PRIVILEGES»òÖ´ÐÐmysqladmin flush-privileges£¨»òÈç¹ûÄãÓÐÒ»¸ö²»Ö§³Öflush-privilegesµÄÀÏ°æ±¾£¬ÓÃmysqladmin reload¡££©¡£

2.2.3 ·¶Î§ÁÐÆ¥Åä˳Ðò

MySQL·þÎñÆ÷°´Ò»ÖÖÌض¨·½Ê½ÅÅÐò·ûÊÚȨ±íÖеļǼ£¬È»ºóͨ¹ý°´Ðòä¯ÀÀ¼Ç¼ƥÅäµ½À´µÄÁ¬½Ó¡£ÕÒµ½µÄµÚÒ»¸öÆ¥Åä¾ö¶¨Á˱»Ê¹ÓõļǼ¡£Àí½âMySQLʹÓõÄÅÅÐò˳ÐòºÜÖØÒª£¬ÌرðÊǶÔuser±í¡£

µ±·þÎñÆ÷¶ÁÈ¡user±íÄÚÈÝʱ£¬Ëü¸ù¾ÝÔÚHostºÍUserÁÐÖеÄÖµÅÅÐò¼Ç¼£¬HostÖµÆð¾ö¶¨×÷Óã¨ÏàͬµÄHostÖµÅÅÔÚÒ»Æð£¬È»ºóÔÙ¸ù¾ÝUserÖµÅÅÐò£©¡£È»¶ø£¬ÅÅÐò²»ÊǵäÐò£¨°´´ÊÅÅÐò£©£¬ËüÖ»ÊDz¿·ÖÊÇ¡£ÒªÀμǵÄÊÇ×ÖÃæÉϵĴÊÓÅÏÈÓÚģʽ¡£ÕâÒâζ×ÅÈç¹ûÄãÕý´Óclient.your.netÁ¬½Ó·þÎñÆ÷¶øHostÓÐclient.your.netºÍ%.your.netÁ½¸öÖµ£¬ÔòµÚÒ»¸öÏÈÑ¡¡£ÀàËƵأ¬%.your.netÓÅÏÈÓÚ%.net£¬È»ºóÊÇ%¡£IPµØÖ·µÄÆ¥ÅäÒ²ÊÇÕâÑùµÄ¡£

×ÜÖ®Ò»¾ä»°£¬Ô½¾ßÌåÔ½ÓÅÏÈ¡£¿ÉÒԲμû±¾Îĸ½Â¼µÄʵÀý¡£

2.3 ±ÜÃâÊÚȨ±í·çÏÕ

±¾½ì½éÉÜһЩÔÚÄãÊÚȨʱµÄһЩԤ·À´ëÊ©£¬ÒÔ¼°²»Ã÷ÖµµÄÑ¡Ôñ´øÀ´µÄ·çÏÕ¡£Ò»°ãµØ£¬ÄãÒªºÜ¡°ÁßØÄ¡±µØÊÚÓ賬¼¶Óû§È¨ÏÞ£¬¼´²»ÒªÆôÓÃ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ÁÐµÄ±í£º

USER test;

CREATE TABLE tmp (b LONGBLOB);

ʹÓøñí¶Áȡÿ¸ö¶ÔÓ¦ÓÚÄãÏë͵ȡµÄÊý¾Ý¿â±íÎļþµÄÄÚÈÝ£¬È»ºó½«±íÄÚÈÝдÈëÄã×Ô¼ºÊý¾Ý¿âµÄÒ»¸öÎļþÖУº

LOAD DATA INFILE "./other_db/x.frm" INTO TABLE tmp

   FIELDS ESCAPED BY "" LINES TERMINATED BY "";

SELECT * FROM tmp INTO OUTFILE "y.frm"

   FIELDS ESCAPED BY "" LINES TERMINATED BY "";

DELETE FROM tmp;

LOAD DATA INFILE "./other_db/x.ISD" INTO TABLE tmp

   FIELDS ESCAPED BY "" LINES TERMINATED BY "";

SELECT * FROM tmp INTO OUTFILE "y.ISD"

   FIELDS ESCAPED BY "" LINES TERMINATED BY "";

DELETE FROM tmp;

LOAD DATA INFILE "./other_db/x.ISM" INTO TABLE tmp

   FIELDS ESCAPED BY "" LINES TERMINATED BY "";

SELECT * FROM tmp INTO OUTFILE "y.ISM"

ÏÖÔÚÄãÓµÓÐÁËÒ»¸öбíy£¬Ëü°üº¬other_db.xµÄÄÚÈݲ¢ÇÒÄãÓÐȫȨ·ÃÎÊËü¡£

Ϊ±ÜÃâÈÃÈËÒÔͬÑùµÄ·½Ê½¹¥»÷£¬¸ù¾Ý¡°µÚÒ»²¿·Ö ÄÚ²¿°²È«ÐÔ-±£»¤ÄãµÄÊý¾ÝĿ¼¡±ÖеÄÖ¸ÁîÉèÖÃÄãµÄÊý¾ÝĿ¼ÉϵÄȨÏÞ¡£ÄãÒ²¿ÉÒÔÔÚÄãÆô¶¯·þÎñÆ÷ʱʹÓÃ--skip-show-databaseÑ¡ÏîÏÞÖÆÓû§¶ÔÓÚËûÃÇûÓ÷ÃÎÊȨÏÞµÄÊý¾Ý¿âʹÓÃSHOW DATABASESºÍSHOW TABLES¡£ÕâÓÐÖúÓÚ·ÀÖ¹Óû§ÕÒµ½¹ØÓÚËüÃDz»ÄÜ·ÃÎʵÄÊý¾Ý¿âºÍ±íµÄÐÅÏ¢¡£

ALTERȨÏÞÄÜÒÔ²»Ï£ÍûµÄ·½Ê½Ê¹Ó᣼ٶ¨ÄãÏëÈÃuser1¿ÉÒÔ·ÃÎÊtable1µ«²»ÄÜ·ÃÎÊtables2¡£Ò»¸öÓµÓÐALTERȨÏÞµÄÓû§¿ÉÒÔͨ¹ýʹÓÃALTER TABLE½«table2¸ÄÃûΪtable1À´ÍµÁº»»Öù¡£

µ±ÐÄGRANTȨÏÞ¡£Á½¸öÓɲ»Í¬È¨ÏÞµ«¶¼ÓÐGRANTȨÏÞµÄÓû§¿ÉÒÔʹ±Ë´ËµÄȨÀû¸üÇ¿´ó¡£

2.4 ²»ÓÃGRANTÉèÖÃÓû§

Èç¹ûÄãÓÐÒ»¸öÔçÓÚ3.22.11µÄMySQL°æ±¾£¬Äã²»ÄÜʹÓÃGRANT£¨»òREVOKE£©Óï¾äÉèÖÃÓû§¼°Æä·ÃÎÊȨÏÞ£¬µ«Äã¿ÉÒÔÖ±½ÓÐÞ¸ÄÊÚȨ±íµÄÄÚÈÝ¡£Èç¹ûÄãÀí½âGRANTÓï¾äÈçºÎÐÞ¸ÄÊÚȨ±í£¬ÕâºÜÈÝÒס£ÄÇôÄãͨ¹ýÊÖ¹¤·¢³öINSERTÓï¾ä¾ÍÄÜ×Ô¼º×öͬÑùµÄÊÂÇé¡£

µ±Äã·¢³öÒ»ÌõGRANTÓï¾äʱ£¬ÄãÖ¸¶¨Ò»¸öÓû§ÃûºÍÖ÷»úÃû£¬¿ÉÄÜ»¹ÓпÚÁî¡£¶Ô¸ÃÓû§Éú³ÉÒ»¸öuser±í¼Ç¼£¬²¢ÇÒÕâЩֵ¼Ç¼ÔÚUser¡¢HostºÍPasswordÁÐÖС£Èç¹ûÄãÔÚGRANTÓï¾äÖÐÖ¸¶¨È«¾ÖȨÏÞ£¬ÕâЩȨÏ޼ǼÔڼǼµÄȨÏÞÁÐÖС£ÆäÖÐÒªÁôÉñµÄÊÇGRANTÓï¾äΪÄã¼ÓÃÜ¿ÚÁ¶øINSERT²»ÊÇ£¬ÄãÐèÒªÔÚINSERTÖÐʹÓÃPASSWORD()º¯Êý¼ÓÃÜ¿ÚÁî¡£

Èç¹ûÄãÖ¸¶¨Êý¾Ý¿â¼¶È¨ÏÞ£¬Óû§ÃûºÍÖ÷»úÃû±»¼Ç¼ÔÚdb±íµÄUserºÍHostÁС£ÄãΪÆäÊÚȨµÄÊý¾Ý¿â¼Ç¼ÔÚDbÁÐÖУ¬ÄãÊÚÓèµÄȨÏ޼ǼÔÚȨÏÞÁÐÖС£

¶ÔÓÚ±í¼¶ºÍÁм¶È¨ÏÞ£¬Ð§¹ûÊÇÀàËƵġ£ÔÚtables_privºÍcolumns_priv±íÖд´½¨¼Ç¼ÒԼǼÓû§Ãû¡¢Ö÷»úÃûºÍÊý¾Ý¿â£¬»¹ÓÐÏà¹ØµÄ±íºÍÁС£ÊÚÓèµÄȨÏ޼ǼÔÚȨÏÞÁÐÖС£

Èç¹ûÄ㻹¼ÇµÃÇ°ÃæµÄ½éÉÜ£¬ÄãÓ¦¸ÃÄܼ´Ê¹²»ÓÃGRANTÓï¾äÒ²ÄÜ×öGRANT×öµÄÊÂÇé¡£¼ÇסÔÚÄãÖ±½ÓÐÞ¸ÄÊÚȨ±íʱ£¬Ä㽫֪ͨ·þÎñÆ÷ÖØÔØÊÚȨ±í£¬·ñÔòËû²»ÖªµÀÄãµÄ¸Ä±ä¡£Äã¿ÉÒÔÖ´ÐÐÒ»¸ömysqladmin flush-privileges»òmysqladmin reloadÃüÁîÇ¿ÆÈÒ»¸öÖØÔØ¡£Èç¹ûÄãÍü¼Ç×öÕâ¸ö£¬Äã»áÒÉ»óΪʲô·þÎñÆ÷²»×öÄãÏë×öµÄÊÂÇé¡£

ÏÂÁÐGRANTÓï¾ä´´½¨Ò»¸öÓµÓÐËùÓÐȨµÄ³¬¼¶Óû§¡£°üÀ¨ÊÚȨ¸ø±ðÈ˵ÄÄÜÁ¦£º

GRANT ALL ON *.* TO anyname@localhost IDENTIFIED BY "passwd"

  WITH GRANT OPTION

¸ÃÓï¾ä½«ÔÚuser±íÖÐΪanyname@localhost´´½¨Ò»¸ö¼Ç¼£¬´ò¿ªËùÓÐȨÏÞ£¬ÒòΪÕâÀïÊdz¬¼¶Óû§£¨È«¾Ö£©È¨ÏÞ´æ´¢µÄµØ·½£¬ÒªÓÃINSERTÓï¾ä×öͬÑùµÄÊÂÇ飬Óï¾äÊÇ£º

INSERT INTO user VALUES("localhost","anyname",PASSWORD("passwd"),

  "Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y","Y")

Äã¿ÉÄÜ·¢ÏÖËü²»¹¤×÷£¬ÕâÒª¿´ÄãµÄMySQL°æ±¾¡£ÊÚȨ±íµÄ½á¹¹ÒѾ­¸Ä±ä¶øÇÒÄãÔÚÄãµÄuser±í¿ÉÄÜûÓÐ14¸öȨÏÞÁС£ÓÃSHOW COLUMNSÕÒ³öÄãµÄÊÚȨ±í°üº¬µÄÿ¸öȨÏÞÁУ¬ÏàÓ¦µØµ÷ÕûÄãµÄINSERTÓï¾ä¡£ ÏÂÁÐGRANTÓï¾äÒ²´´½¨Ò»¸öÓµÓг¬¼¶Óû§Éí·ÝµÄÓû§£¬µ«ÊÇÖ»ÓÐÒ»¸öµ¥¸öµÄȨÏÞ£º

GRANT RELOAD ON *.* TO flush@localhost IDENTIFIED BY "flushpass"

±¾ÀýµÄINSERTÓï¾ä±ÈÇ°Ò»¸ö¼òµ¥£¬ËüºÜÈÝÒ×ÁгöÁÐÃû²¢Ö»Ö¸¶¨Ò»¸öȨÏÞÁС£ËùÓÐÆäËüÁн«ÉèÖÃΪȱʡµÄ"N"£º

INSERT INTO user (Host,Password,Reload) VALUES("localhost","flush",PASSWORD("flushpass"),"Y")

Êý¾Ý¿â¼¶È¨ÏÞÓÃÒ»¸öON db_name.*×Ó¾ä¶ø²»ÊÇON *.*½øÐÐÊÚȨ£º

GRANT ALL ON sample.* TO boris@localhost IDENTIFIED BY "ruby"

ÕâЩȨÏÞ²»ÊÇÈ«¾ÖµÄ£¬ËùÒÔËüÃDz»´æ´¢ÔÚuser±íÖУ¬ÎÒÃÇÈÔÈ»ÐèÒªÔÚuser±íÖд´½¨Ò»Ìõ¼Ç¼£¨Ê¹µÃÓû§ÄÜÁ¬½Ó£©£¬µ«ÎÒÃÇÒ²ÐèÒª´´½¨Ò»¸ödb±í¼Ç¼¼Ç¼Êý¾Ý¿â¼¯È¨ÏÞ£º

INSERT INTO user (Host,User,Password) VALUES("localhost","boris",PASSWORD("ruby"))

INSERT INTO db VALUES("localhost","sample_db","boris","Y","Y","Y","Y","Y","Y","N","Y","Y","Y")

"N"ÁÐÊÇΪGRANTȨÏÞ£»¶ÔĩβµÄÒ»¸öÊý¾Ý¿â¼¶¾ßÓÐWITH GRANT OPTIONµÄGRANTÓï¾ä£¬ÄãÒªÉèÖøÃÁÐΪ"Y"¡£

ÒªÉèÖÃ±í¼¶»òÁм¶È¨ÏÞ£¬Äã¶Ôtables_priv»òcolumns_privʹÓÃINSERTÓï¾ä¡£µ±È»£¬Èç¹ûÄãûÓÐGRANTÓï¾ä£¬Ä㽫ûÓÐÕâЩ±í£¬ÒòΪËüÃÇÔÚMySQLÖÐͬʱ³öÏÖ¡£Èç¹ûÄãȷʵÓÐÕâЩ±í²¢ÇÒΪÁËijЩԭÒòÏëÒªÊÖ¹¤²Ù×÷ËüÃÇ£¬ÒªÖªµÀÄã²»ÄÜÓõ¥¶ÀµÄÁÐÆôÓÃȨÏÞ¡£

ÄãÉèÖÃtables_priv.Table_priv»òcolumns_priv.Column_privÁÐÀ´ÉèÖðüº¬ÄãÏëÆôÓõÄȨÏÞÖµ¡£ÀýÈ磬Ҫ¶ÔÒ»¸ö±íÆôÓÃSELECTºÍINSERTȨÏÞ£¬ÄãÒªÔÚÏà¹ØµÄtables_privµÄ¼Ç¼ÖÐÉèÖÃTable_privΪ"Select,Insert"¡£

Èç¹ûÄãÏë¶ÔÒ»¸öÓµÓÐMySQLÕ˺ŵÄÓû§ÐÞ¸ÄȨÏÞ£¬Ê¹ÓÃUPDATE¶ø²»ÊÇINSERT£¬²»¹ÜÄãÔö¼Ó»ò³·ÏúȨÏÞ¶¼ÊÇÕâÑù¡£ÒªÍêȫɾ³ýÒ»¸öÓû§£¬´ÓÓû§Ê¹ÓõÄÿ¸ö±íÖÐɾ³ý¼Ç¼¡£

Èç¹ûÄãÔ¸Òâ±ÜÃâ·¢Ò»¸ö²éѯÀ´Ö±½ÓÐÞ¸ÄȫȨ±í£¬Äã¿ÉÒÔ¿´Ò»ÏÂMySQL×Ô´øµÄmysqlaccessºÍmysql_setpermissions½Å±¾¡£

¸½Â¼1 С²âÑé

ÔÚÄã¸Õ¸Õа²×°ÁËÒ»¸öMySQL·þÎñÆ÷£¬ÔÚÄãÔö¼ÓÁËÒ»¸öÔÊÐíÁ¬½ÓMySQLµÄÓû§£¬ÓÃÏÂÁÐÓï¾ä£º

GRANT ALL ON samp_db.* TO fred@*.snake.net IDENTIFIED "cocoa"

¶øfredÅöÇÉÔÚ·þÎñÆ÷Ö÷»úÉÏÓиöÕ˺ţ¬ËùÒÔËûÊÔͼÁ¬½Ó·þÎñÆ÷£º

%mysql -u fred -pcocoa samp_db

ERROR 1045: Access denied for user: 'fred@localhost' (Using password: YES)

Ϊʲô£¿

Ô­ÒòÊÇ£º

ÏÈ¿¼ÂÇÒ»ÏÂmysql_install_dbÈçºÎ½¨Á¢³õʼȨÏÞ±íºÍ·þÎñÆ÷ÈçºÎʹÓÃuser±í¼Ç¼ƥÅä¿Í»§Á¬½Ó¡£ÔÚÄãÓÃmysql_install_db³õʼ»¯ÄãµÄÊý¾Ý¿âʱ£¬Ëü´´½¨ÀàËÆÕâÑùµÄuser±í£º

Host User

localhost

pit.snake.net

localhost

pit.snake.net root

root

Í·Á½¸ö¼Ç¼ÔÊÐírootÖ¸¶¨localhost»òÖ÷»úÃûÁ¬½Ó±¾µØ·þÎñÆ÷£¬ºóÁ½¸öÔÊÐíÄäÃûÓû§´Ó±¾µØÁ¬½Ó¡£µ±Ôö¼ÓfredÓû§ºó£¬

Host User

localhost

pit.snake.net

localhost

pit.snake.net

%.snake.net root

root

fred

ÔÚ·þÎñÆ÷Æô¶¯Ê±£¬Ëü¶ÁÈ¡¼Ç¼²¢ÅÅÐòËüÃÇ£¨Ê×ÏÈ°´Ö÷»ú£¬È»ºó°´Ö÷»úÉϵÄÓû§£©£¬Ô½¾ßÌåÔ½ÅÅÔÚÇ°Ã棺

Host User

localhost

localhost

pit.snake.net

pit.snake.net

%.snake.net root

root

fred

ÓÐlocalhostµÄÁ½¸ö¼Ç¼ÅÅÔÚÒ»Æ𣬶ø¶ÔrootµÄ¼Ç¼ÅÅÔÚµÚÒ»£¬ÒòΪËü±È¿ÕÖµ¸ü¾ßÌå¡£pit.snake.netµÄ¼Ç¼ҲÀàËÆ¡£ËùÓÐÕâЩ¾ùÊÇûÓÐÈκÎͨÅä·ûµÄ×ÖÃæÉϵÄHostÖµ£¬ËùÒÔËüÃÇÅÅÔÚ¶Ôfred¼Ç¼µÄÇ°Ã棬ÌرðÊÇÄäÃûÓû§ÅÅÔÚfred֮ǰ¡£

½á¹ûÊÇÔÚfredÊÔͼ´ÓlocalhostÁ¬½Óʱ£¬HostÁÐÖеÄÒ»¸ö¿ÕÓû§ÃûµÄ¼Ç¼ÔÚ°üº¬%.snake.netµÄ¼Ç¼ǰƥÅä¡£¸Ã¼Ç¼µÄ¿ÚÁîÊǿյģ¬ÒòΪȱʡµÄÄäÃûÓû§Ã»ÓпÚÁî¡£ÒòΪÔÚfredÁ¬½Óʱָ¶¨ÁËÒ»¸ö¿ÚÁÓÉÒ»¸ö´íÅäÇÒÁ¬½Óʧ°Ü¡£

ÕâÀïÒª¼ÇסµÄÊÇ£¬ËäÈ»ÓÃͨÅä·ûÖ¸¶¨Óû§¿ÉÒÔ´ÓÆäÁ¬½ÓµÄÖ÷»úÊǺܷ½±ã¡£µ«Äã´Ó±¾µØÖ÷»úÁ¬½Óʱ»áÓÐÎÊÌ⣬ֻҪÄãÔÚtable±íÖб£ÁôÄäÃûÓû§¼Ç¼¡£

Ò»°ãµØ£¬½¨ÒéÄãɾ³ýÄäÃûÓû§¼Ç¼£º

mysql> DELETE FROM user WHERE User="";

¸ü½øÒ»²½£¬Í¬Ê±É¾³ýÆäËûÊÚȨ±íÖеÄÈκÎÄäÃûÓû§£¬ÓÐUserÁеıíÓÐdb¡¢tables_privºÍcolumns_priv¡£

¸½Â¼2 ʹһ¸öеÄMySQL°²×°¸ü°²È«

ÔÚÄã×Ô¼º°²×°ÁËÒ»¸öеÄMySQL·þÎñÆ÷ºó£¬ÄãÐèҪΪMySQLµÄrootÓû§Ö¸¶¨Ò»¸öĿ¼£¨È±Ê¡ÎÞ¿ÚÁ£¬·ñÔòÈç¹ûÄãÍü¼ÇÕâµã£¬Ä㽫ÄãµÄMySQL´¦ÓÚ¼«²»°²È«µÄ״̬£¨ÖÁÉÙÔÚÒ»¶Îʱ¼äÄÚ£©¡£

ÔÚUnix£¨Linux£©ÉÏ£¬ÔÚ°´ÕÕÊÖ²áµÄÖ¸Áî°²×°ºÃMySQLºó£¬Äã±ØÐëÔËÐÐmysql_install_db½Å±¾½¨Á¢°üº¬ÊÚȨ±íµÄmysqlÊý¾Ý¿âºÍ³õʼȨÏÞ¡£ÔÚWindowsÉÏ£¬ÔËÐзַ¢ÖеÄSetup³ÌÐò³õʼ»¯Êý¾ÝĿ¼ºÍmysqlÊý¾Ý¿â¡£¼Ù¶¨·þÎñÆ÷Ò²ÔÚÔËÐС£

µ±ÄãµÚÒ»´ÎÔÚ»úÆ÷ÉÏ°²×°MySQLʱ£¬mysqlÊý¾Ý¿âÖеÄÊÚȨ±íÊÇÕâÑù³õʼ»¯µÄ£º

Äã¿ÉÒÔ´Ó±¾µØÖ÷»ú£¨localhost£©ÉÏÒÔrootÁ¬½Ó¶ø²»Ö¸¶¨¿ÚÁî¡£rootÓû§ÓµÓÐËùÓÐȨÏÞ£¨°üÀ¨¹ÜÀíȨÏÞ£©²¢¿É×öÈκÎÊÂÇé¡££¨Ë³±ã˵Ã÷£¬MySQL³¬¼¶Óû§ÓëUnix³¬¼¶Óû§ÓÐÏàͬµÄÃû×Ö£¬ËûÃDZ˴˺ÁÎÞ¹Øϵ¡££©

ÄäÃû·ÃÎʱ»ÊÚÓèÓû§¿É´Ó±¾µØÁ¬½ÓÃûΪtestºÍÈκÎÃû×ÖÒÔtest_¿ªÊ¼µÄÊý¾Ý¿â¡£ÄäÃûÓû§¿É¶ÔÊý¾Ý¿â×öÈκÎÊÂÇ飬µ«ÎÞ¹ÜÀíȨÏÞ¡£

´Ó±¾µØÖ÷»ú¶à·þÎñÆ÷µÄÁ¬½ÓÊÇÔÊÐíµÄ£¬²»¹ÜÁ¬½ÓµÄÓû§Ê¹ÓÃÒ»¸ölocalhostÖ÷»úÃû»òÕæʵÖ÷»úÃû¡£È磺

% mysql -h localhost test

% mysql -h pit.snake.net test

ÄãÒÔrootÁ¬½ÓMySQLÉõÖÁ²»Ö¸¶¨¿ÚÁîµÄÊÂʵֻÊÇÒâζ×ųõʼ°²×°²»°²È«£¬ËùÒÔ×÷Ϊ¹ÜÀíÔ±µÄÄãÊ×ÏÈÒª×öµÄÓ¦¸ÃÊÇÉèÖÃroot¿ÚÁȻºó¸ù¾ÝÄãÉèÖÿÚÁîʹÓõķ½·¨£¬ÄãÒ²¿ÉÒÔ¸æËß·þÎñÆ÷ÖØÔØÊÚȨ±íÊÇËüÖªµÀÕâ¸ö¸Ä±ä¡££¨ÔÚ·þÎñÆ÷Æô¶¯Ê±£¬ËüÖØÔØ±íµ½ÄÚ´æÖжø¿ÉÄܲ»ÖªµÀÄãÒѾ­ÐÞ¸ÄÁËËüÃÇ¡££©

¶ÔMySQL 3.22ºÍÒÔÉÏ°æ±¾£¬Äã¿ÉÒÔÓÃmysqladminÉèÖÿÚÁ

% mysqladmin -u root password yourpassword

¶ÔÓÚMySQLµÄÈκΰ汾£¬Äã¿ÉÒÔÓÃmysql³ÌÐò²¢Ö±½ÓÐÞ¸ÄmysqlÊý¾Ý¿âÖеÄuserÊÚȨ±í£º

% mysql -u root mysql

mysql>UPDATE user SET password=PASSWORD("yourpassword") WHERE User="root";

Èç¹ûÄãÓÐMySQLµÄÀÏ°æ±¾£¬Ê¹ÓÃmysqlºÍUPDATE¡£

ÔÚÄãÉèÖÃÍê¿ÚÁîºó£¬Í¨¹ýÔËÐÐÏÂÁÐÃüÁî¼ì²éÄãÊÇ·ñÐèÒª¸æËß·þÎñÆ÷ÖØÔØÊÚȨ±í£º

% mysqladmin -u root status

Èç¹û·þÎñÆ÷ÈÔÈ»ÈÃÄãÒÔroot¶ø²»Ö¸¶¨¿ÚÁî¶øÁ¬½Ó·þÎñÆ÷£¬ÖØÔØÊÚȨ±í£º

% mysqladmin -u root reload

ÔÚÄãÉèÖÃÁËrootµÄ¿ÚÁîºó£¨²¢ÇÒÈç¹ûÐèÒªÖØÔØÁËÊÚȨ±í£©£¬Ä㽫ÐèÒªÔÚÈκÎʱºòÒÔrootÁ¬½Ó·þÎñÆ÷ʱָ¶¨¿ÚÁî¡£

¡ª¡ªÕª×Ô£ºêÌ×Ó¹¤×÷ÊÒ

¡¾·µ»Ø¶¥²¿¡¿ ¡¾´òÓ¡±¾Ò³¡¿ ¡¾¹Ø±Õ´°¿Ú¡¿

¹ØÓÚÎÒÃÇ / ¸øÎÒÁôÑÔ / °æȨ¾Ù±¨ / Òâ¼û½¨Òé / ÍøÕ¾±à³ÌQQȺ   
Copyright ©2003- 2024 Lihuasoft.net webmaster(at)lihuasoft.net ¼ÓÔØʱ¼ä 0.00193