|
|
MySQLÖÐÎIJο¼ÊÖ²á7(MySQL ´æȡȨÏÞϵͳ) grant ÉèÖÃÃÜÂë password |
|
|
×÷ÕߣºÎ´Öª À´Ô´£ºÔ¹âÈí¼þÕ¾ ¼ÓÈëʱ¼ä£º2005-2-28¡¡Ô¹âÈí¼þÕ¾ |
MySQLÖÐÎIJο¼ÊÖ²á7(MySQL ´æȡȨÏÞϵͳ) תÔØ ÒëÕߣºêÌ×Ó
¡¼·µ»Ø¡½¡¼×ª·¢¡½
ÒëÕߣºêÌ×Ó (clyan@sohu.com)Ö÷Ò³£ºhttp://linuxdb.yeah.net 6 MySQL ´æȡȨÏÞϵͳ MySQLÓÐÒ»¸öÏȽøµ«·Ç±ê×¼µÄ°²È«/ȨÏÞϵͳ¡£±¾½ÚÃèÊöËüµÄ¹¤×÷ÔÀí¡£
6.1 ȨÏÞϵͳ×öʲô MySQLȨÏÞϵͳµÄÖ÷Òª¹¦ÄÜÊÇ֤ʵÁ¬½Óµ½Ò»Ì¨¸ø¶¨Ö÷»úµÄÒ»¸öÓû§£¬²¢ÇÒ¸³Óè¸ÃÓû§ÔÚÒ»¸öÊý¾Ý¿âÉÏselect¡¢ insert¡¢updateºÍdeleteµÄȨÏÞ¡£
¸½¼ÓµÄ¹¦ÄÜ°üÀ¨ÓÐÒ»¸öÄäÃûµÄÓû§ºÍ¶ÔÓÚMySQLÌض¨µÄ¹¦ÄÜÀýÈçLOAD DATA INFILE½øÐÐÊÚȨ¼°¹ÜÀí²Ù×÷µÄÄÜÁ¦¡£
6.2 MySQL Óû§ÃûºÍ¿ÚÁî ÓÉMySQLʹÓÃÓû§ÃûºÍ¿ÚÁîµÄ·½·¨ÓëUnix»òWindowsʹÓõķ½Ê½Óкܶ಻֮ͬ´¦£º
- MySQLʹÓÃÓÚÈÏ֤ĿµÄµÄÓû§Ãû£¬ÓëUnixÓû§Ãû(µÇ¼Ãû×Ö)»òWindowsÓû§ÃûÎ޹ء£È±Ê¡µØ£¬´ó¶àÊýMySQL¿Í»§³¢ÊÔʹÓõ±Ç°UnixÓû§Ãû×÷ΪMySQLÓû§ÃûµÇ¼£¬µ«ÊÇÕâ½ö½öΪÁË·½±ã¡£¿Í»§³ÌÐòÔÊÐíÓÃ-u»ò--userÑ¡ÏîÖ¸¶¨Ò»¸ö²»Í¬µÄÃû×Ö£¬ÕâÒâζ×ÅÎÞÂÛÈçºÎÄã²»ÄÜʹµÃÒ»¸öÊý¾Ý¿â¸ü°²È«£¬³ý·ÇËùÓеÄMySQLÓû§Ãû¶¼ÓпÚÁî¡£ÈκÎÈË¿ÉÒÔÊÔͼÓÃÈκÎÃû×ÖÁ¬½Ó·þÎñÆ÷£¬¶øÇÒÈç¹ûËûÃÇÖ¸¶¨ÁËûÓпÚÁîµÄÈκÎÃû×Ö£¬ËûÃǽ«³É¹¦¡£
- MySQLÓû§Ãû×¿ÉÒÔÊÇ16¸÷×Ö·û£»µäÐ͵أ¬UnixÓû§ÃûÏÞÖÆΪ8¸ö×Ö·û¡£
- MySQL¿ÚÁîÓëUnix¿ÚÁîû¹Øϵ¡£ÔÚÄãʹÓõǼµ½Ò»Ì¨Unix»úÆ÷¿ÚÁîºÍÄãʹÓÃÔÚÄÇ̨»úÆ÷ÉÏ´æÈ¡Ò»¸öÊý¾Ý¿âµÄ¿ÚÁîÖ®¼äûÓбØÒªÓйØÁª¡£
- MySQL¼ÓÃÜ¿ÚÁîʹÓÃÁËÒ»¸öUnixµÇ¼ÆÚ¼äËùÓõIJ»Í¬Ëã·¨£¬¼û7.4.12 ÔÓÏÊýÒ»½ÚÖÐÃèÊöPASSWORD()ºÍENCRYPT()º¯Êý²¿·Ö¡£
6.3 ÓëMySQL·þÎñÆ÷Á¬½Ó µ±ÄãÏëÒª´æÈ¡Ò»¸öMySQL·þÎñÆ÷ʱ£¬MySQL¿Í»§³ÌÐòÒ»°ãÒªÇóÄãÖ¸¶¨Á¬½Ó²ÎÊý£ºÄãÏëÒªÁª½ÓµÄÖ÷»ú¡¢ÄãµÄÓû§ÃûºÍÄãµÄ¿ÚÁî¡£ÀýÈ磬mysql¿Í»§¿ÉÒÔÏóÕâÑùÆô¶¯(¿ÉÑ¡µÄ²ÎÊý±»°üÀ¨ÔÚ¡°[¡±ºÍ¡°]¡±Ö®¼ä)£º
shell> mysql [-h host_name][-u user_name][-pyour_pass ] -h, -uºÍ-pÑ¡ÏîµÄÁíÒ»ÖÖÐÎʽÊÇ--host=host_name¡¢--user=user_nameºÍ--password=your_pass¡£×¢ÒâÔÚ-p»ò--password=Óë¸úËæËüºóÃæµÄ¿ÚÁîÖ®¼äûÓпոñ¡£
×¢Ò⣺ÔÚÃüÁîÐÐÉÏÖ¸¶¨Ò»¸ö¿ÚÁîÊDz»°²È«µÄ£¡ËæºóÔÚÄãϵͳÉϵÄÈκÎÓû§¿ÉÒÔͨ¹ý´òÀàËÆÕâÑùµÄÃüÁî·¢ÏÖÄãµÄ¿ÚÁps auxww¡£¼û4.15.4 Ñ¡ÏîÎļþ¡£
¶ÔÓÚÃüÁîÐÐûÓеÄÁª½Ó²ÎÊý£¬mysqlʹÓÃȱʡֵ£º
- ȱʡÖ÷»úÃûÊÇlocalhost¡£
- ȱʡÓû§ÃûÊÇÄãµÄUnixµÇ¼Ãû¡£
- Èç¹ûûÓÐ-p£¬ÔòûÓÐÌṩ¿ÚÁî¡£
ÕâÑù, ¶ÔÒ»¸öUnixÓû§joe£¬ÏÂÁÐÃüÁîÊǵȼ۵ģº
shell>mysql -h localhost -u joe shell>mysql -h localhost shell>mysql -u joe shell>mysql
ÆäËüMySQL¿Í»§³ÌÐòÓÐͬÑù±íÏÖ¡£
ÔÚUnixϵͳÉÏ£¬µ±Äã½øÐÐÒ»¸öÁ¬½Óʱ£¬Äã¿ÉÒÔÖ¸¶¨ÒªÊ¹ÓõIJ»Í¬µÄȱʡֵ£¬ÕâÑùÄã²»±Øÿ´ÎÔÚÄãµ÷ÓÃÒ»¸ö¿Í»§³ÌÐòÊÇÔÚÃüÁîÐÐÉÏÊäÈëËûÃÇ¡£Õâ¿ÉÒÔÓкܶ෽·¨×öµ½£º
ÄãÄÜÔÚÄãµÄÖ÷Ŀ¼Ï¡°.my.cnf¡±µÄÅäÖÃÎļþµÄ[client]С½ÚÀïÖ¸¶¨Á¬½Ó²ÎÊý¡£ÎļþµÄÏà¹ØС½Ú¿´ÉÏÈ¥¿ÉÄÜÏñÕâÑù£º [client] host=host_name user=user_name password=your_pass
¼û4.15.4 Ñ¡ÏîÎļþ¡£
Äã¿ÉÒÔÓû·¾³±äÁ¿Ö¸¶¨Á¬½Ó²ÎÊý¡£Ö÷»ú¿ÉÓÃMYSQL_HOSTÖ¸¶¨£¬MySQLÓû§Ãû×Ö¿ÉÓÃUSERÖ¸¶¨(½ö¶Ô Windows)£¬¿ÚÁî¿ÉÓÃMYSQL_PWDÖ¸¶¨£¨µ«ÊÇÕâ²»°²È«£¬¼ûÏÂÒ»½Ú) ¡£ Èç¹ûÁ¬½Ó²ÎÊýÒÔ¶àÖÖ·½·¨±»Ö¸¶¨£¬ÔÚÃüÁîÐÐÉϱ»Ö¸¶¨µÄÖµÓÅÏÈÓÚÔÚÅäÖÃÎļþºÍ»·¾³±äÁ¿ÖÐÖ¸¶¨µÄÖµ£¬¶øÔÚÅäÖÃÎļþÖ¸¶¨µÄÖµÓÅÏÈÓÚÔÚ»·¾³±äÁ¿Ö¸¶¨µÄÖµ¡£
6.4 ʹÄãµÄ¿ÚÁȫ ÒÔÒ»ÖÖ±©Â¶µÄ¿É±»ÆäËûÓû§·¢Ïֵķ½Ê½Ö¸¶¨ÄãµÄ¿ÚÁîÊDz»Í×µ±µÄ¡£µ±ÄãÔËÐпͻ§³ÌÐòʱ£¬Äã¿ÉÒÔʹÓÃÏÂÁз½·¨Ö¸¶¨ÄãµÄ¿ÚÁ»¹ÓÐÿ¸ö·½·¨µÄ·çÏÕÆÀ¹À£º
- ʹÓÃÒ»¸öÔÚÃüÁîÐÐÉÏ-pyour_pass»ò--password=your_passµÄÑ¡Ïî¡£ÕâºÜ·½±ãµ«ÊDz»°²È«£¬ÒòΪÄãµÄ¿ÚÁî¶Ôϵͳ״̬³ÌÐò(ÀýÈçps)±äµÃ¿É¼û£¬Ëü¿ÉÒÔ±»ÆäËûµÄÓû§µ÷ÓÃÀ´ÏÔʾÃüÁîÐС£(Ò»°ãMySQL¿Í»§ÔÚËûÃǵijõʼ»¯Ë³ÐòÆÚ¼äÓÃÁ㸲¸ÇÃüÁîÐвÎÊý£¬µ«ÊÇÈÔÈ»ÓÐÒ»¸ö¶ÌÔݼä¸ôʱ¼äÄÚ²ÎÊýÖµ¿É¼ûµÄ¡££©
- ʹÓÃÒ»¸ö-p»ò--passwordÑ¡Ïî(ûÓÐÖ¸¶¨your_passÖµ)¡£ÔÚÕâÖÖÇé¿öÏ£¬¿Í»§³ÌÐòÇëÇóÀ´×ÔÖն˵ĿÚÁ
shell>mysql - u user_name - p Enter password: ********
¿Í»§»ØÓ¦¡°*¡±×Ö·ûµ½×÷ΪÊäÈëÄãµÄ¿ÚÁîµÄÖÕ¶ËʹµÃÅÔ¹ÛÕß²»ÄÜ¿´¼ûËü¡£ÒòΪËü¶ÔÆäËûÓû§²»¿É¼û£¬ÓëÔÚÃüÁîÐÐÉÏÖ¸¶¨ËüÏà±È£¬ÕâÑù½øÈëÄãµÄ¿ÚÁî¸ü°²È«¡£È»¶ø£¬Õâ¸öÊäÈëÒ»¸ö¿ÚÁîµÄ·½·¨½ö½öΪÄã½»»¥Ê½ÔËÐгÌÐòÊǺÏÊʵġ£Èç¹ûÄãÏëÒª´Ó·Ç½»»¥Ê½ÔËÐеÄÒ»¸ö½Å±¾µ÷ÓÃÒ»¸ö¿Í»§£¬¾ÍûÓдÓÖÕ¶ËÊäÈëÈë¿ÚÁîµÄ»ú»á¡£
ÔÚÒ»¸öÅäÖÃÎļþÖд洢ÄãµÄ¿ÚÁî¡£ÀýÈ磬Äã¿ÉÄãµÄÖ÷Ŀ¼µÄ¡°.my.cnf¡±ÎļþÖеÄ[client]½ÚÁгöÄãµÄ¿ÚÁ [client] password=your_pass
Èç¹ûÄãÔÚ¡°.my.cnf¡±ÀïÃæ´æ´¢¿ÚÁÎļþÓ¦¸Ã²»ÊÇ×é»òÊÀ½ç¿É¶Á»ò¿ÉдµÄ¡£±£Ö¤ÎļþµÄ´æȡģʽÊÇ400»ò600¡£¼û4.15.4 Ñ¡ÏîÎļþ¡£
Äã¿ÉÔÚMYSQL_PWD»·¾³±äÁ¿Öд洢¿ÚÁµ«ÊÇÕâ¸ö·½·¨±ØÐëÏëµ½ÊǼ«²»°²È«µÄÇÒÓ¦¸Ã²»Ê¹Óá£psµÄijЩ°æ±¾°üÀ¨ÏÔʾÔËÐнø³ÌµÄ»·¾³µÄÑ¡ÏÈç¹ûÄãÉ趨MYSQL_PWD£¬ÄãµÄ¿ÚÁ¶ÔËùÓÐÈËÊÇÏÔ¶øÒ×¼ûµÄ£¬ÉõÖÁÔÚûÓÐÕâÑùÒ»¸ö°æ±¾µÄpsϵͳÉÏ£¬¼ÙÉèûÓÐÆäËû·½·¨¹Û²ìµ½½ø³Ì»·¾³ÊDz»Ã÷Öǵġ£ ×ÜÖ®£¬×ȫµÄ·½·¨ÊÇÈÿͻ§³ÌÐòÌáʾ¿ÚÁî»òÔÚÒ»¸öÊʵ±±£»¤µÄ¡°.my.cnf¡±ÎļþÖÐÖ¸¶¨¿ÚÁî¡£
6.5 MySQLÌṩµÄȨÏÞ È¨ÏÞÐÅÏ¢ÓÃuser¡¢db¡¢host¡¢tables_privºÍcolumns_priv±í±»´æ´¢ÔÚmysqlÊý¾Ý¿âÖÐ(¼´ÔÚÃûΪmysqlµÄÊý¾Ý¿âÖÐ)¡£ÔÚMySQLÆô¶¯Ê±ºÍÔÚ6.9 ȨÏÞÐ޸ĺÎʱÉúЧËù˵µÄÇé¿öʱ£¬·þÎñÆ÷¶ÁÈëÕâЩÊý¾Ý¿â±íÄÚÈÝ¡£
±¾ÊÖ²áËùÓõÄÉæ¼°ÓÉMySQLÌṩµÄȨÏÞÃû³ÆÏÔʾÔÚÏÂ±í£¬»¹ÓÐÔÚÊÚȨ±íÖÐÿ¸öȨÏ޵ıíÁÐÃû³ÆºÍÿ¸öȨÏÞÓйصÄÉÏÏÂÎÄ£º
ȨÏÞ ÁÐ ÉÏÏÂÎÄ select Select_priv ±í insert Insert_priv ±í update Update_priv ±í delete Delete_priv ±í index Index_priv ±í alter Alter_priv ±í create Create_priv Êý¾Ý¿â¡¢±í»òË÷Òý drop Drop_priv Êý¾Ý¿â»ò±í grant Grant_priv Êý¾Ý¿â»ò±í references References_priv Êý¾Ý¿â»ò±í reload Reload_priv ·þÎñÆ÷¹ÜÀí shutdown Shutdown_priv ·þÎñÆ÷¹ÜÀí process Process_priv ·þÎñÆ÷¹ÜÀí file File_priv ÔÚ·þÎñÆ÷ÉϵÄÎļþ´æÈ¡
select¡¢insert¡¢updateºÍdeleteȨÏÞÔÊÐíÄãÔÚÒ»¸öÊý¾Ý¿âÏÖÓеıíÉÏʵʩ²Ù×÷¡£
SELECTÓï¾äÖ»ÓÐÔÚËûÃÇÕæÕý´ÓÒ»¸ö±íÖмìË÷ÐÐÊDzÅÐèÒªselectȨÏÞ£¬Äã¿ÉÒÔÖ´ÐÐij¸öSELECTÓï¾ä£¬ÉõÖÁûÓÐÈκε½·þÎñÆ÷ÉϵÄÊý¾Ý¿âÀïµÄ´æÈ¡Èκζ«Î÷µÄÐí¿É¡£ÀýÈ磬Äã¿ÉʹÓÃmysql¿Í»§×÷Ϊһ¸ö¼òµ¥µÄ¼ÆËãÆ÷£º
mysql> SELECT 1+1; mysql> SELECT PI()*2;
indexȨÏÞÔÊÐíÄã´´½¨»òÅ×Æú(ɾ³ý)Ë÷Òý¡£
alterȨÏÞÔÊÐíÄãʹÓÃALTER TABLE¡£
createºÍdropȨÏÞÔÊÐíÄã´´½¨ÐµÄÊý¾Ý¿âºÍ±í£¬»òÅ×Æú(ɾ³ý)ÏÖ´æµÄÊý¾Ý¿âºÍ±í¡£
×¢Ò⣺Èç¹ûÄ㽫mysqlÊý¾Ý¿âµÄdropȨÏÞÊÚÓèÒ»¸öÓû§£¬¸ÃÓû§ÄÜÅ×Æú´æ´¢ÁËMySQL´æȡȨÏÞµÄÊý¾Ý¿â£¡
grantȨÏÞÔÊÐíÄã°ÑÄã×Ô¼ºÓµÓеÄÄÇЩȨÏÞÊÚ¸øÆäËûµÄÓû§¡£
fileȨÏÞ¸øÓèÄãÓÃLOAD DATA INFILEºÍSELECT ... INTO OUTFILEÓï¾ä¶ÁºÍд·þÎñÆ÷ÉϵÄÎļþ£¬Èκα»ÊÚÓèÕâ¸öȨÏÞµÄÓû§¶¼ÄܶÁ»òдMySQL·þÎñÆ÷ÄܶÁ»òдµÄÈκÎÎļþ¡£
ÆäÓàµÄȨÏÞÓÃÓÚ¹ÜÀíÐÔ²Ù×÷£¬ËüʹÓÃmysqladmin³ÌÐòʵʩ¡£Ï±íÏÔʾmysqladminÖ§Åäÿ¸ö¹ÜÀíÐÔȨÏÞÔÊÐíÄãÖ´ÐеÄÃüÁ
ÓÅ»Ý È¨ÏÞÓµÓÐÕßÔÊÐíÖ´ÐеÄÃüÁî reload reload, refresh, flush-privileges, flush-hosts, flush-logs, flush-tables shutdown shutdown precess processlist, kill
reloadÃüÁî¸æËß·þÎñÆ÷ÔÙ¶ÁÈëÊÚȨ±í£¬refreshÃüÁîÇåÏ´ËùÓÐ±í²¢´ò¿ªºÍ¹Ø±Õ¼Ç¼Îļþ£¬flush-privilegesÊÇreloadµÄÒ»¸öͬÒå´Ê£¬ÆäËüflush-*ÃüÁîÖ´ÐÐÀàËÆrefreshµÄ¹¦ÄÜ£¬µ«ÊÇ·¶Î§¸üÓÐÏÞ£¬²¢ÇÒÔÚijЩÇé¿öÏ¿ÉÄܸüºÃÓá£ÀýÈ磬Èç¹ûÄãÖ»ÊÇÏëÇåÏ´¼Ç¼Îļþ£¬flush-logs±ÈrefreshÊǸüºÃµÄÑ¡Ôñ¡£
shutdownÃüÁî¹Øµô·þÎñÆ÷¡£
processlistÃüÁîÏÔʾÔÚ·þÎñÆ÷ÄÚÖ´ÐеÄÏ̵߳ÄÐÅÏ¢¡£killÃüÁîɱËÀ·þÎñÆ÷Ï̡߳£Äã×ÜÊÇÄÜÏÔʾ»òɱËÀÄã×Ô¼ºµÄỊ̈߳¬µ«ÊÇÄãÐèÒªprocessȨÏÞÀ´ÏÔʾ»òɱËÀÆäËûÓû§Æô¶¯µÄÏ̡߳£
×ܵÄ˵À´£¬Ö»ÊÚÓèȨÏÞ¸øÐèÒªËûÃǵÄÄÇЩÓû§ÊÇÒ»¸öºÃÖ÷Ò⣬µ«ÊÇÄãÓ¦¸ÃÔÚÊÚÓèij¸öȨÏÞʱÊÔÑéÌض¨µÄ¾¯¸æ£º
- grantȨÏÞÔÊÐíÓû§·ÅÆúËûÃǵÄȨÏÞ¸øÆäËûÓû§¡£2¸öÓв»Í¬µÄȨÏÞ²¢ÓÐgrantȨÏÞµÄÓû§¿ÉÒԺϲ¢È¨ÏÞ¡£
- alterȨÏÞ¿ÉÒÔÓÃÓÚͨ¹ýÖØÐÂÃüÃû±íÀ´ÍƷȨÏÞϵͳ¡£
- fileȨÏÞ¿ÉÒÔ±»ÀÄÓÃÔÚ·þÎñÆ÷É϶ÁÈ¡ÈκÎÊÀ½ç¿É¶Á(world-readable£¬¼´ÈκÎÈ˿ɶÁ)µÄÎļþµ½Ò»ÕÅÊý¾Ý¿â±í£¬È»ºóÆäÄÚÈÝÄÜÓÃSELECT±»´æÈ¡¡£
- shutdownȨÏÞͨ¹ýÖÕÖ¹·þÎñÆ÷¿ÉÒÔ±»ÀÄÓÃÍêÈ«¾Ü¾øΪÆäËûÓû§·þÎñ, ¡£
- precessȨÏÞÄܱ»ÓÃÀ´²ì¿´µ±Ç°Ö´ÐеIJéѯµÄÆÕͨÎı¾£¬°üÀ¨É趨»ò¸Ä±ä¿ÚÁî²éѯ¡£
- ÔÚmysqlÊý¾Ý¿âÉϵÄȨÏÞÄܱ»ÓÃÀ´¸Ä±ä¿ÚÁîºÍÆäËû´æȡȨÏÞÐÅÏ¢¡££¨¿ÚÁî±»¼ÓÃÜ´æ´¢£¬ËùÒÔÒ»¸ö¶ñÒâµÄÓû§²»Äܼòµ¥µØ¶ÁÈ¡ËûÃÇ¡£È»¶ø£¬ÓÐ×ã¹»µÄȨÏÞ£¬Í¬Ò»¸öÓû§ÄÜÓò»Í¬µÄÒ»¸ö´úÌæÒ»¸ö¿ÚÁî¡££©
ÓÐһЩÊÂÇéÄã²»ÄÜÓÃMySQLȨÏÞϵͳ×öµ½£º
- Äã²»ÄÜÃ÷ÏÔµØÖ¸¶¨Ò»¸ö¸ø¶¨Óû§Ó¦¸Ã±»¾Ü¾ø´æÈ¡¡£¼´£¬Äã²»ÄÜÃ÷ÏÔµØÆ¥ÅäÒ»¸öÓû§²¢ÇÒÈ»ºó¾Ü¾øÁ¬½Ó¡£
- Äã²»ÄÜÖ¸¶¨Ò»¸öÓû§ÓÐȨ´´½¨Á¢»òÅ×ÆúÒ»¸öÊý¾Ý¿âÖÐµÄ±í£¬Ò²²»ÄÜ´´½¨»òÅ×ÆúÊý¾Ý¿â±¾Éí¡£
6.6 ȨÏÞϵͳ¹¤×÷ÔÀí MySQLȨÏÞϵͳ±£Ö¤ËùÓеÄÓû§¿ÉÒÔÑϸñµØ×öËûÃǼٶ¨±»ÔÊÐí×öµÄÊÂÇé¡£µ±ÄãÁ¬½ÓÒ»¸öMySQL·þÎñÆ÷ʱ£¬ ÄãµÄÉí·ÝÓÉÄã´ÓÄÇÁ¬½ÓµÄÖ÷»úºÍÄãÖ¸¶¨µÄÓû§ÃûÀ´¾ö¶¨£¬ÏµÍ³¸ù¾ÝÄãµÄÉí·ÝºÍÄãÏë×öʲôÀ´ÊÚÓèȨÏÞ¡£
MySQLÔÚÈ϶¨Éí·ÝÖп¼ÂÇÄãµÄÖ÷»úÃûºÍÓû§Ãû×Ö£¬ÊÇÒòΪÓкÜСµÄÔÒò¼Ù¶¨Ò»¸ö¸ø¶¨µÄÓû§ÔÚÒòÌØÍøÉÏÊôÓÚͬһ¸öÈË¡£ÀýÈ磬Óû§´Ówhitehouse.govÁ¬½ÓµÄbill²»±ØºÍ´Ómosoft.comÁ¬½ÓbillÊÇͬһ¸öÈË¡£ MySQLͨ¹ýÔÊÐíÄãÇø·ÖÔÚ²»Í¬µÄÖ÷»úÉÏÅöÇÉÓÐͬÑùÃû×ÖÓû§À´´¦ÀíËü£ºÄã¿ÉÒÔ¶Ô´Ówhitehouse.govÁ¬½ÓÊÚÓëbillÒ»¸öȨÏÞ¼¯£¬¶øΪ´Ómicrosoft.comµÄÁ¬½ÓÊÚÓèÒ»¸ö²»Í¬µÄȨÏÞ¼¯¡£
MySQL´æÈ¡¿ØÖÆ°üº¬2¸ö½×¶Î£º
- ½×¶Î1£º·þÎñÆ÷¼ì²éÄãÊÇ·ñÔÊÐíÁ¬½Ó¡£
- ½×¶Î2£º¼Ù¶¨ÄãÄÜÁ¬½Ó£¬·þÎñÆ÷¼ì²éÄã·¢³öµÄÿ¸öÇëÇ󡣿´ÄãÊÇ·ñÓÐ×ã¹»µÄȨÏÞʵʩËü¡£ÀýÈ磬Èç¹ûÄã´ÓÊý¾Ý¿âÖÐÒ»¸ö±í¾«Ñ¡(select)Ðлò´ÓÊý¾Ý¿âÅ×ÆúÒ»¸ö±í£¬·þÎñÆ÷È·¶¨Äã¶Ô±íÓÐselectȨÏÞ»ò¶ÔÊý¾Ý¿âÓÐdropȨÏÞ¡£
·þÎñÆ÷ÔÚ´æÈ¡¿ØÖƵÄÁ½¸ö½×¶ÎʹÓÃÔÚmysqlµÄÊý¾Ý¿âÖеÄuser¡¢dbºÍhost±í£¬ÔÚÕâЩÊÚȨ±íÖÐ×Ö¶ÎÈçÏ£º
±íÃû³Æ user db host ·¶Î§×ֶΠHost Host Host User Db Db Password User ȨÏÞ×ֶΠSelect_priv Select_priv Select_priv Insert_priv Insert_priv Insert_priv Update_priv Update_priv Update_priv Delete_priv Delete_priv Delete_priv Index_priv Index_priv Index_priv Alter_priv Alter_priv Alter_priv Create_priv Create_priv Create_priv Drop_priv Drop_priv Drop_priv Grant_priv Grant_priv Grant_priv Reload_priv Shutdown_priv Process_priv File_priv
¶Ô´æÈ¡¿ØÖƵĵڶþ½×¶Î(ÇëÇó֤ʵ)£¬Èç¹ûÇëÇóÉæ¼°±í£¬·þÎñÆ÷¿ÉÒÔÁíÍâ²Î¿¼tables_privºÍcolumns_priv±í¡£ÕâЩ±íµÄ×Ö¶ÎÈçÏ£º
±íÃû³Æ tables_priv columns_priv ·¶Î§×ֶΠHost Host Db Db User User Table_name Table_name Column_name ȨÏÞ×ֶΠTable_priv Column_priv Column_priv ÆäËû×ֶΠTimestamp Timestamp Grantor
ÿ¸öÊÚȨ±í°üº¬·¶Î§×ֶκÍȨÏÞ×ֶΡ£
·¶Î§×ֶξö¶¨±íÖÐÿ¸öÌõÄ¿µÄ·¶Î§£¬¼´£¬ÌõÄ¿ÊÊÓõÄÉÏÏÂÎÄ¡£ÀýÈç, Ò»¸öuser±íÌõÄ¿µÄHostºÍUserֵΪ'thomas.loc.gov'ºÍ'bob'½«±»ÓÃÓÚ֤ʵÀ´×ÔÖ÷»úthomas.loc.govµÄbob¶Ô·þÎñÆ÷µÄÁ¬½Ó¡£Í¬Ñù£¬Ò»¸ödb±íÌõÄ¿µÄHost¡¢UserºÍDb×ֶεÄÖµÊÇ'thomas.loc.gov'¡¢'bob'ºÍ'reports'½«ÓÃÔÚbob´ÓÖ÷»úÁª½Óthomas.loc.gov´æÈ¡reportsÊý¾Ý¿âµÄʱºò¡£ tables_privºÍcolumns_priv±í°üº¬·¶Î§×ֶΣ¬Ö¸³öÿ¸öÌõÄ¿ÊÊÓõıí»ò±í£¯ÁеÄ×éºÏ¡£
¶ÔÓÚ¼ì²é´æÈ¡µÄÓÃ;£¬±È½ÏHostÖµÊǺöÂÔ´óСдµÄ¡£User¡¢Password¡¢DbºÍTable_nameÖµÊÇÇø·Ö´óСдµÄ¡£Column_nameÖµÔÚMySQL3.22.12»òÒÔºó°æ±¾ÊǺöÂÔ´óСдµÄ¡£
ȨÏÞ×Ö¶ÎÖ¸³öÓÉÒ»¸ö±íÌõÄ¿ÊÚÓèµÄȨÏÞ£¬¼´£¬¿Éʵʩʲô²Ù×÷¡£·þÎñÆ÷×éºÏ¸÷ÖÖµÄÊÚȨ±íµÄÐÅÏ¢ÐγÉÒ»¸öÓû§È¨ÏÞµÄÍêÕûÃèÊö¡£Îª´ËʹÓõĹæÔòÔÚ6.8 ´æÈ¡¿ØÖÆ, ½×¶Î2£ºÇëÇó֤ʵÃèÊö¡£
·¶Î§×Ö¶ÎÊÇ×Ö·û´®£¬ÈçÏÂËùÊö£»Ã¿¸ö×ֶεÄȱʡֵÊÇ¿Õ×Ö·û´®£º
×Ö¶ÎÃû ÀàÐÍ Host CHAR(60) User CHAR(16) Password CHAR(16) Db CHAR(64) (tables_privºÍcolumns_priv±íΪCHAR(60)£©
ÔÚuser¡¢dbºÍhost±íÖУ¬ËùÓÐȨÏÞ×ֶα»ÉùÃ÷ΪENUM('N','Y')--ÿһ¸ö¶¼¿ÉÓÐÖµ'N'»ò'Y'£¬²¢ÇÒȱʡֵÊÇ'N'.
ÔÚtables_privºÍcolumns_priv±íÖУ¬È¨ÏÞ×ֶα»ÉùÃ÷ΪSET×ֶΣº
±íÃû ×Ö¶ÎÃû ¿ÉÄܵļ¯ºÏ³ÉÔ± tables_priv Table_priv 'Select', 'Insert', 'Update', 'Delete', 'Create', 'Drop', 'Grant', 'References', 'Index', 'Alter' tables_priv Column_priv 'Select', 'Insert', 'Update', 'References' columns_priv Column_priv 'Select', 'Insert', 'Update', 'References'
¼òµ¥µØ˵£¬·þÎñÆ÷ʹÓÃÕâÑùµÄÊÚȨ±í£º
- user±í·¶Î§×ֶξö¶¨ÊÇ·ñÔÊÐí»ò¾Ü¾øµ½À´µÄÁ¬½Ó¡£¶ÔÓÚÔÊÐíµÄÁ¬½Ó£¬È¨ÏÞ×Ö¶ÎÖ¸³öÓû§µÄÈ«¾Ö(³¬¼¶Óû§)ȨÏÞ¡£
- dbºÍhost±íÒ»ÆðʹÓãº
db±í·¶Î§×ֶξö¶¨Óû§ÄÜ´ÓÄĸöÖ÷»ú´æÈ¡ÄĸöÊý¾Ý¿â¡£È¨ÏÞ×ֶξö¶¨ÔÊÐíÄĸö²Ù×÷¡£ µ±ÄãÏëÒªÒ»¸ö¸ø¶¨µÄdbÌõÄ¿Ó¦ÓÃÓÚÈô¸ÉÖ÷»úʱ£¬host±í×÷Ϊdb±íµÄÀ©Õ¹±»Ê¹Óá£ÀýÈ磬Èç¹ûÄãÏëÒªÒ»¸öÓû§ÄÜÔÚÄãµÄÍøÂç´ÓÈô¸ÉÖ÷»úʹÓÃÒ»¸öÊý¾Ý¿â£¬ÔÚÓû§µÄdb±íµÄHostÌõÄ¿ÉèΪ¿ÕÖµ£¬È»ºó½«ÄÇЩÖ÷»úµÄÿһ¸öÒÆÈëhost±í¡£Õâ¸ö»úÖÆÏêϸÃèÊöÔÚ6.8 ´æÈ¡¿ØÖÆ, ½×¶Î2£ºÇëÇó֤ʵ¡£
- tables_privºÍcolumns_priv±íÀàËÆÓÚdb±í£¬µ«ÊǸü¾«Ö£ºËûÃÇÔÚ±íºÍÁм¶Ó¦Óöø·ÇÔÚÊý¾Ý¿â¼¶¡£
×¢Òâ¹ÜÀíȨÏÞ(reload, shutdown, µÈµÈ)½öÔÚuser±íÖб»Ö¸¶¨¡£ÕâÊÇÒòΪ¹ÜÀíÐÔ²Ù×÷ÊÇ·þÎñÆ÷±¾ÉíµÄ²Ù×÷²¢ÇÒ²»ÊÇÌض¨Êý¾Ý¿â£¬Òò´ËûÓÐÀíÓÉÔÚÆäËûÊÚȨ±íÖÐÁгöÕâÑùµÄȨÏÞ¡£ÊÂʵÉÏ£¬Ö»ÐèÒªÇë½Ìuser±íÀ´¾ö¶¨ÄãÊÇ·ñÖ´ÐÐÒ»¸ö¹ÜÀí²Ù×÷¡£
fileȨÏÞÒ²½öÔÚuser±íÖÐÖ¸¶¨¡£Ëü²»ÊǹÜÀíÐÔȨÏÞ£¬µ«Äã¶Á»òлÔÚ·þÎñÆ÷Ö÷»úÉϵÄÎļþµÄµÄÄÜÁ¦¶ÀÁ¢ÓÚÄãÕýÔÚ´æÈ¡µÄÊý¾Ý¿â¡£
µ±mysqld·þÎñÆ÷Æô¶¯Ê±£¬¶ÁÈ¡Ò»´ÎÊÚȨ±íÄÚÈÝ¡£¶ÔÊÚȨ±íµÄ¸ü¸ÄÉúЧÔÚ6.9 ȨÏÞ¸ü¸ÄºÎʱÉúЧÃèÊö¡£
µ±ÄãÐÞ¸ÄÊÚȨ±íµÄÄÚÈÝʱ£¬È·±£Äã°´ÄãÏëÒªµÄ·½Ê½¸ü¸ÄȨÏÞÉèÖÃÊÇÒ»¸öºÃÖ÷Ò⡣Ϊ°ïÖúÕï¶ÏÎÊÌ⣬¼û6.13 ¡°´æÈ¡¾Ü¾øÒýÆ𡱴íÎóµÄÔÒò¡£¶ÔÓÚ°²È«ÎÊÌâÉϵÄÖҸ棬¼û6.14 Ôõô¶ÔʹMySQL°²È«¶Ô¿¹½âÃܸßÊÖ¡£
Ò»¸öÓÐÓõÄÕï¶Ï¹¤¾ßÊÇmysqlaccess½Å±¾£¬ÓÉCarlier Yves Ìṩ¸øMySQL·Ö·¢¡£Ê¹ÓÃ--helpÑ¡Ïîµ÷ÓÃmysqlaccess²éÃ÷ËüÔõÑù¹¤×÷¡£×¢Ò⣺mysqlaccess½öÓÃuser¡¢dbºÍhost±í½ö¼ì²é´æÈ¡¡£Ëü²»¼ì²é±í»òÁм¶È¨ÏÞ¡£
6.7 ´æÈ¡¿ØÖÆ, ½×¶Î1£ºÁ¬½Ó֤ʵ µ±ÄãÊÔͼÁª½ÓÒ»¸öMySQL·þÎñÆ÷ʱ£¬·þÎñÆ÷»ùÓÚÄãµÄÉí·ÝºÍÄãÊÇ·ñÄÜͨ¹ý¹©Ó¦ÕýÈ·µÄ¿ÚÁîÑéÖ¤Éí·ÝÀ´½ÓÊÜ»ò¾Ü¾øÁ¬½Ó¡£Èç¹û²»ÊÇ£¬·þÎñÆ÷ÍêÈ«¾ß½áÄãµÄ´æÈ¡£¬·ñÔò£¬·þÎñÆ÷½ÓÊÜÁ¬½Ó£¬È»ºó½øÈë½×¶Î2²¢ÇҵȴýÇëÇó¡£
ÄãµÄÉí·Ý»ùÓÚ2¸öÐÅÏ¢£º
- Äã´ÓÄǸöÖ÷»úÁ¬½Ó
- ÄãµÄMySQLÓû§Ãû
Éí·Ý¼ì²éʹÓÃ3¸öuser±í(Host, UserºÍPassword)·¶Î§×Ö¶ÎÖ´ÐС£·þÎñÆ÷Ö»ÓÐÔÚÒ»¸öuser±íÌõÄ¿Æ¥ÅäÄãµÄÖ÷»úÃûºÍÓû§Ãû²¢ÇÒÄãÌṩÁËÕýÈ·µÄ¿ÚÁîʱ²Å½ÓÊÜÁ¬½Ó¡£
ÔÚuser±í·¶Î§×ֶοÉÒÔÈçϱ»Ö¸¶¨£º
- Ò»¸öHostÖµ¿ÉÒÔÊÇÖ÷»úÃû»òÒ»¸öIPÊý×Ö£¬»ò'localhost'Ö¸³ö±¾µØÖ÷»ú¡£
- Äã¿ÉÒÔÔÚHost×Ö¶ÎÀïʹÓÃͨÅä·û×Ö·û¡°%¡±ºÍ¡°_¡±¡£
- Ò»¸öHostÖµ'%'Æ¥ÅäÈκÎÖ÷»úÃû£¬Ò»¸ö¿Õ°×HostÖµµÈ¼ÛÓÚ'%'¡£×¢ÒâÕâЩֵƥÅäÄÜ´´½¨Ò»¸öÁ¬½Óµ½ÄãµÄ·þÎñÆ÷µÄÈκÎÖ÷»ú£¡
ͨÅä·û×Ö·ûÔÚUser×Ö¶ÎÖв»ÔÊÐí£¬µ«ÊÇÄãÄÜÖ¸¶¨¿Õ°×µÄÖµ£¬ËüÆ¥ÅäÈκÎÃû×Ö¡£Èç¹ûuser±íÆ¥Åäµ½À´µÄÁ¬½ÓµÄÌõÄ¿ÓÐÒ»¸ö¿Õ°×µÄÓû§Ãû£¬Óû§±»ÈÏΪÊÇÄäÃûÓû§(ûÓÐÃû×ÖµÄÓû§)£¬¶ø·Ç¿Í»§Êµ¼ÊÖ¸¶¨µÄÃû×Ö¡£ÕâÒâζ×ÅÒ»¸ö¿Õ°×µÄÓû§Ãû±»ÓÃÓÚÔÚÁ¬½ÓÆÚ¼äµÄ½øÒ»²½µÄ´æÈ¡¼ì²é(¼´£¬Ôڽ׶Î2ÆÚ¼ä)¡£
- Password×ֶοÉÒÔÊǿհ׵ġ£Õâ²»Òâζ×ÅÆ¥ÅäÈκοÚÁËüÒâζ×ÅÓû§±ØÐë²»Ö¸¶¨Ò»¸ö¿ÚÁî½øÐÐÁ¬½Ó¡£
·Ç¿Õ°×PasswordÖµ´ú±í¼ÓÃܵĿÚÁî¡£ MySQL²»ÒÔÈκÎÈË¿ÉÒÔ¿´µÄ´¿Îı¾¸ñʽ´æ´¢¿ÚÁÏà·´£¬ÕýÔÚÊÔͼÁª½ÓµÄÒ»¸öÓû§ÌṩµÄ¿ÚÁî±»¼ÓÃÜ(ʹÓÃPASSWORD()º¯Êý)£¬²¢ÇÒÓë´æ´¢ÁËuser±íÖеÄÒѾ¼ÓÃܵİ汾±È½Ï¡£Èç¹ûËûÃÇÆ¥Å䣬¿ÚÁîÊÇÕýÈ·µÄ¡£
ÏÂÃæµÄÀý×ÓÏÔʾ³ö¸÷ÖÖuser±íÖÐHostºÍUserÌõÄ¿µÄÖµµÄ×éºÏÈçºÎÓ¦ÓÃÓÚµ½À´µÄÁ¬½Ó£º
Host Öµ User Öµ ±»ÌõÄ¿Æ¥ÅäµÄÁ¬½Ó 'thomas.loc.gov' 'fred' fred, ´Óthomas.loc.gov Á¬½Ó 'thomas.loc.gov' '' ÈκÎÓû§, ´Óthomas.loc.govÁ¬½Ó '%' 'fred' fred, ´ÓÈκÎÖ÷»úÁ¬½Ó '%' '' ÈκÎÓû§, ´ÓÈκÎÖ÷»úÁ¬½Ó '%.loc.gov' 'fred' fred, ´ÓÔÚloc.govÓòµÄÈκÎÖ÷»úÁ¬½Ó 'x.y.%' 'fred' fred, ´Óx.y.net¡¢x.y.com,x.y.eduµÈÁª½Ó¡££¨Õâ»òÐíÎÞÓã© '144.155.166.177' 'fred' fred, ´ÓÓÐ144.155.166.177 IP µØÖ·µÄÖ÷»úÁ¬½Ó '144.155.166.%' 'fred' fred, ´Ó144.155.166 CÀà×ÓÍøµÄÈκÎÖ÷»úÁ¬½Ó
¼ÈÈ»ÄãÄÜÔÚHost×Ö¶ÎʹÓÃIPͨÅä·ûÖµ(ÀýÈ磬'144.155.166.%'Æ¥ÅäÔÚÒ»¸ö×ÓÍøÉϵÄÿ̨Ö÷»ú)£¬ÓпÉÄÜijÈË¿ÉÄÜÆóͼ̽¾¿ÕâÖÖÄÜÁ¦£¬Í¨¹ýÃüÃûһ̨Ö÷»úΪ144.155.166.somewhere.com¡£ÎªÁË×èÖ¹ÕâÑùµÄÆóͼ£¬MySQL²»ÔÊÐíÆ¥ÅäÒÔÊý×ÖºÍÒ»¸öµãÆðʼµÄÖ÷»úÃû£¬ÕâÑù£¬Èç¹ûÄãÓÃÒ»¸öÃüÃûΪÀàËÆ1.2.foo.comµÄÖ÷»ú£¬ËüµÄÃû×Ö¾ö²»»áÆ¥ÅäÊÚȨ±íÖÐHostÁС£Ö»ÓÐÒ»¸öIPÊý×ÖÄÜÆ¥ÅäIPͨÅä·ûÖµ¡£
Ò»¸öµ½À´µÄÁ¬½Ó¿ÉÒÔ±»ÔÚuser±íÖеij¬¹ýÒ»¸öÌõÄ¿Æ¥Åä¡£ÀýÈ磬һ¸öÓÉfred´Óthomas.loc.govµÄÁ¬½ÓÆ¥Åä¶à¸öÌõÄ¿ÈçÉÏËùÊö¡£Èç¹û³¬¹ýÒ»¸öÆ¥Å䣬·þÎñÆ÷ÔõôѡÔñʹÓÃÄĸöÌõÄ¿ÄØ£¿·þÎñÆ÷ÔÚÆô¶¯Ê±¶ÁÈëuser±íºóͨ¹ýÅÅÐòÀ´½â¾öÕâ¸öÎÊÌ⣬Ȼºóµ±Ò»¸öÓû§ÊÔͼÁ¬½Óʱ£¬ÒÔÅÅÐòµÄ˳Ðòä¯ÀÀÌõÄ¿£¬µÚÒ»¸öÆ¥ÅäµÄÌõÄ¿±»Ê¹Óá£
user±íÅÅÐò¹¤×÷ÈçÏ£¬¼Ù¶¨user±í¿´ÆðÀ´ÏñÕâÑù£º
+-----------+----------+- | Host | User | ... +-----------+----------+- | % | root | ... | % | jeffrey | ... | localhost | root | ... | localhost | | ... +-----------+----------+-
µ±·þÎñÆ÷ÔÚ±íÖжÁȡʱ£¬ËüÒÔ×îÌض¨µÄHostֵΪÏȵĴÎÐòÅÅÁÐ('%'ÔÚHostÁÐÀïÒâζ×Å¡°ÈκÎÖ÷»ú¡±²¢ÇÒÊÇ×î²»Ìض¨µÄ)¡£ÓÐÏàͬHostÖµµÄÌõÄ¿ÒÔ×îÌض¨µÄUserֵΪÏȵĴÎÐòÅÅÁÐ(Ò»¸ö¿Õ°×UserÖµÒâζ×Å¡°ÈκÎÓû§¡±²¢ÇÒÊÇ×î²»Ìض¨µÄ)¡£×îÖÕÅÅÐòµÄuser±í¿´ÆðÀ´ÏñÕâÑù£º
+-----------+----------+- | Host | User | ... +-----------+----------+- | localhost | root | ... | localhost | | ... | % | jeffrey | ... | % | root | ... +-----------+----------+-
µ±Ò»¸öÁ¬½Ó±»³¢ÊÔʱ£¬·þÎñÆ÷ä¯ÀÀÅÅÐòµÄÌõÄ¿²¢Ê¹ÓÃÕÒµ½µÄµÚÒ»¸öÆ¥Åä¡£¶ÔÓÚÓÉjeffrey´ÓlocalhostµÄÒ»¸öÁ¬½Ó£¬ÔÚHostÁеÄ'localhost'ÌõÄ¿Ê×ÏÈÆ¥Åä¡£ÄÇЩÓпհ×Óû§ÃûµÄÌõÄ¿Æ¥ÅäÁ¬½ÓµÄÖ÷»úÃûºÍÓû§Ãû¡££¨'%'/'jeffrey'ÌõÄ¿Ò²½«Æ¥Å䣬µ«ÊÇËü²»ÊÇÔÚ±íÖеĵÚһƥÅä¡££©
ÕâÊÇÁíÍâÒ»¸öÀý×Ó¡£¼Ù¶¨user±í¿´ÆðÀ´ÏñÕâÑù£º
+----------------+----------+- | Host | User | ... +----------------+----------+- | % | jeffrey | ... | thomas.loc.gov | | ... +----------------+----------+-
ÅÅÐòºóµÄ±í¿´ÆðÀ´ÏñÕâÑù£º
+----------------+----------+- | Host | User | ... +----------------+----------+- | thomas.loc.gov | | ... | % | jeffrey | ... +----------------+----------+-
Ò»¸öÓÉjeffrey´Óthomas.loc.govµÄÁ¬½Ó±»µÚÒ»¸öÌõÄ¿Æ¥Å䣬¶øÒ»¸öÓÉjeffrey´Ówhitehouse.govµÄÁ¬½Ó±»µÚ¶þ¸öÆ¥Åä¡£
ÆÕ±éµÄÎó½âÊÇÈÏΪ£¬¶ÔÒ»¸ö¸ø¶¨µÄÓû§Ãû£¬µ±·þÎñÆ÷ÊÔͼ¶ÔÁ¬½ÓÑ°ÕÒÆ¥Åäʱ£¬Ã÷È·ÃüÃûÄǸöÓû§µÄËùÓÐÌõÄ¿½«Ê×Ïȱ»Ê¹Óá£ÕâÃ÷ÏÔ²»ÊÇÊÂʵ¡£ÏÈÇ°µÄÀý×Ó˵Ã÷ÁËÕâµã£¬ÔÚÄÇÀïÒ»¸öÓÉjeffrey´Óthomas.loc.govµÄÁ¬½Óû±»°üº¬'jeffrey'×÷ΪUser×Ö¶ÎÖµµÄÌõÄ¿Æ¥Å䣬µ«ÊÇÓÉûÓÐÓû§ÃûµÄÌâÄ¿Æ¥Å䣡
Èç¹ûÄãÓзþÎñÆ÷Á¬½ÓµÄÎÊÌ⣬´òÓ¡³öuser±í²¢ÇÒÊÖ¹¤ÅÅÐòËü¿´¿´µÚÒ»¸öÆ¥ÅäÔÚÄĶù½øÐС£
6.8 ´æÈ¡¿ØÖÆ£¬½×¶Î2£ºÇëÇó֤ʵ Ò»µ©Ä㽨Á¢ÁËÒ»¸öÁ¬½Ó£¬·þÎñÆ÷½øÈë½×¶Î2¡£¶ÔÔÚ´ËÁ¬½ÓÉϽøÀ´µÄÿ¸öÇëÇ󣬷þÎñÆ÷¼ì²éÄãÊÇ·ñÓÐ×ã¹»µÄȨÏÞÀ´Ö´ÐÐËü£¬Ëü»ùÓÚÄãÏ£ÍûÖ´ÐеIJÙ×÷ÀàÐÍ¡£ÕâÕýÊÇÔÚÊÚȨ±íÖеÄȨÏÞ×ֶη¢»Ó×÷Óõĵط½¡£ÕâЩȨÏÞ¿ÉÒÔÀ´×Óuser¡¢db¡¢host¡¢tables_priv»òcolumns_priv±íµÄÈκÎÒ»¸ö¡£ÊÚȨ±íÓÃGRANTºÍREVOKEÃüÁî²Ù×÷¡£¼û7.26 GRANTºÍREVOKE ¾ä·¨¡££¨Äã¿ÉÒÔ·¢¾õ²Î¿¼6.6 ȨÏÞϵͳÔõÑù¹¤×÷ºÜÓаïÖú£¬ËüÁгöÁËÔÚÿ¸öȨÏÞ±íÖгÊÏÖµÄ×ֶΡ££©
user±íÔÚÒ»¸öÈ«¾Ö»ù´¡ÉÏÊÚÓ踳ÓèÄãµÄȨÏÞ£¬¸ÃȨÏÞ²»¹Üµ±Ç°µÄÊý¾Ý¿âÊÇʲô¾ùÊÊÓá£ÀýÈ磬Èç¹ûuser±íÊÚÓèÄãdeleteȨÏÞ£¬ Äã¿ÉÒÔɾ³ýÔÚ·þÎñÆ÷Ö÷»úÉÏ´ÓÈκÎÊý¾Ý¿âɾ³ýÐУ¡»»¾ä»°Ëµ£¬user±íȨÏÞÊdz¬¼¶Óû§È¨ÏÞ¡£Ö»°Ñuser±íµÄȨÏÞÊÚÓ賬¼¶Óû§Èç·þÎñÆ÷»òÊý¾Ý¿âÖ÷¹ÜÊÇÃ÷Öǵġ£¶ÔÆäËûÓû§£¬ÄãÓ¦¸Ã°ÑÔÚuser±íÖеÄȨÏÞÉè³É'N'²¢ÇÒ½öÔÚÒ»¸öÌض¨Êý¾Ý¿âµÄ»ù´¡ÉÏÊÚȨ£¬ ʹÓÃdbºÍhost±í¡£
dbºÍhost±íÊÚÓèÊý¾Ý¿âÌض¨µÄȨÏÞ¡£ÔÚ·¶Î§×ֶεÄÖµ¿ÉÒÔÈçϱ»Ö¸¶¨£º
- ͨÅä·û×Ö·û¡°%¡±ºÍ¡°_¡±¿É±»ÓÃÓÚÁ½¸ö±íµÄHostºÍDb×ֶΡ£
- ÔÚdb±íµÄ'%'HostÖµÒâζ×Å¡°ÈκÎÖ÷»ú¡±£¬ÔÚdb±íÖÐÒ»¸ö¿Õ°×HostÖµÒâζ×Å¡°¶Ô½øÒ»²½µÄÐÅÏ¢×Éѯhost±í¡±¡£
- ÔÚhost±íµÄÒ»¸ö'%'»ò¿Õ°×HostÖµÒâζ×Å¡°ÈκÎÖ÷»ú¡±¡£
- ÔÚÁ½¸ö±íÖеÄÒ»¸ö'%'»ò¿Õ°×DbÖµÒâζ×Å¡°ÈκÎÊý¾Ý¿â¡±¡£
- ÔÚÁ½¸ö±íÖеÄÒ»¸ö¿Õ°×UserֵƥÅäÄäÃûÓû§¡£
dbºÍhost±íÔÚ·þÎñÆ÷Æô¶¯Ê±±»¶ÁÈ¡ºÍÅÅÐò(ͬʱËü¶Áuser±í)¡£db±íÔÚHost¡¢DbºÍUser·¶Î§×Ö¶ÎÉÏÅÅÐò£¬²¢ÇÒhost±íÔÚHostºÍDb·¶Î§×Ö¶ÎÉÏÅÅÐò¡£¶ÔÓÚuser±í£¬ÅÅÐòÊ×ÏÈ·ÅÖÃ×îÌض¨µÄֵȻºó×îºó×î²»Ìض¨µÄÖµ£¬²¢ÇÒµ±·þÎñÆ÷Ñ°ÕÒÆ¥ÅäÈëÌõĿʱ£¬ËüʹÓÃËüÕÒµ½µÄµÚÒ»¸öÆ¥Åä¡£
tables_privºÍcolumns_priv±íÊÚÓè±íºÍÁÐÌض¨µÄȨÏÞ¡£ÔÚ·¶Î§×ֶεÄÖµ¿ÉÒÔÈçϱ»Ö¸¶¨£º
- ͨÅä·û¡°%¡±ºÍ¡°_¡±¿ÉÓÃÔÚʹÓÃÔÚÁ½¸ö±íµÄHost×ֶΡ£
- ÔÚÁ½¸ö±íÖеÄÒ»¸ö'%'»ò¿Õ°×HostÒâζ×Å¡°ÈκÎÖ÷»ú¡±¡£
- ÔÚÁ½¸ö±íÖеÄDb¡¢Table_nameºÍColumn_name×ֶβ»ÄÜ°üº¬Í¨Åä·û»ò¿Õ°×¡£
tables_privºÍcolumns_priv±íÔÚHost¡¢DbºÍUser×Ö¶ÎÉϱ»ÅÅÐò¡£ÕâÀàËÆÓÚdb±íµÄÅÅÐò£¬¾¡¹ÜÒòΪֻÓÐHost×ֶοÉÒÔ°üº¬Í¨Åä·û£¬µ«ÅÅÐò¸ü¼òµ¥¡£
ÇëÇó֤ʵ½ø³ÌÔÚÏÂÃæÃèÊö¡££¨Èç¹ûÄãÊìϤ´æÈ¡¼ì²éµÄÔ´´úÂ룬Äã»á×¢Òâµ½ÕâÀïµÄÃèÊöÓëÔÚ´úÂëʹÓõÄËã·¨ÂÔÓв»Í¬¡£ÃèÊöµÈ¼ÛÓÚ´úÂëʵ¼Ê×öµÄ¶«Î÷£»ËüÖ»ÊDz»Í¬ÓÚʹ½âÊ͸ü¼òµ¥¡££©
¶Ô¹ÜÀíÇëÇó(shutdown¡¢reloadµÈµÈ)£¬·þÎñÆ÷½ö¼ì²éuser±íÌõÄ¿£¬ÒòΪÄÇÊÇΨһָ¶¨¹ÜÀíȨÏÞµÄ±í¡£Èç¹ûÌõÄ¿Ðí¿ÉÇëÇóµÄ²Ù×÷£¬´æÈ¡±»ÊÚȨÁË£¬·ñÔò¾Ü¾ø¡£ÀýÈ磬Èç¹ûÄãÏëÒªÖ´ÐÐmysqladmin shutdown£¬µ«ÊÇÄãµÄuser±íÌõĿûÓÐΪÄãÊÚÓèshutdownȨÏÞ£¬´æÈ¡ÉõÖÁ²»Óüì²édb»òhost±í¾Í±»¾Ü¾ø¡££¨ÒòΪËûÃDz»°üº¬Shutdown_privÐÐÁУ¬Ã»ÓÐÕâÑù×öµÄ±ØÒª¡££©
¶ÔÊý¾Ý¿âÓйصÄÇëÇó(insert¡¢updateµÈµÈ)£¬·þÎñÆ÷Ê×ÏÈͨ¹ý²éÕÒuser±íÌõÄ¿À´¼ì²éÓû§µÄÈ«¾Ö(³¬¼¶Óû§)ȨÏÞ¡£Èç¹ûÌõÄ¿ÔÊÐíÇëÇóµÄ²Ù×÷£¬´æÈ¡±»ÊÚȨ¡£Èç¹ûÔÚuser±íÖÐÈ«¾ÖȨÏÞ²»¹»£¬·þÎñÆ÷ͨ¹ý¼ì²édbºÍhost±íÈ·¶¨Ìض¨µÄÓû§Êý¾Ý¿âȨÏÞ£º
- ·þÎñÆ÷ÔÚdb±íµÄHost¡¢DbºÍUser×Ö¶ÎÉϲéÕÒÒ»¸öÆ¥Åä¡£ HostºÍUser¶ÔÓ¦Á¬½ÓÓû§µÄÖ÷»úÃûºÍMySQLÓû§Ãû¡£Db×ֶζÔÓ¦Óû§ÏëÒª´æÈ¡µÄÊý¾Ý¿â¡£Èç¹ûûÓÐHostºÍUserµÄÌõÄ¿£¬´æÈ¡±»¾Ü¾ø¡£
- Èç¹ûdb±íÖеÄÌõÄ¿ÓÐÒ»¸öÆ¥Åä¶øÇÒËüµÄHost×ֶβ»Êǿհ׵ģ¬¸ÃÌõÄ¿¶¨ÒåÓû§µÄÊý¾Ý¿âÌض¨µÄȨÏÞ¡£
- Èç¹ûÆ¥ÅäµÄdb±íµÄÌõÄ¿µÄHost×Ö¶ÎÊǿհ׵ģ¬Ëü±íʾhost±íÁоÙÖ÷»úÓ¦¸Ã±»ÔÊÐí´æÈ¡Êý¾Ý¿âµÄÖ÷»ú¡£ÔÚÕâÖÖÇé¿öÏ£¬ÔÚhost±íÖÐ×÷½øÒ»²½²éÕÒÒÔ·¢ÏÖHostºÍDb×Ö¶ÎÉϵÄÆ¥Åä¡£Èç¹ûûÓÐhost±íÌõÄ¿Æ¥Å䣬´æÈ¡±»¾Ü¾ø¡£Èç¹ûÓÐÆ¥Å䣬Óû§Êý¾Ý¿âÌض¨µÄȨÏÞÒÔÔÚdbºÍhost±íµÄÌõÄ¿µÄȨÏÞ£¬¼´ÔÚÁ½¸öÌõÄ¿¶¼ÊÇ'Y'µÄȨÏ޵Ľ»¼¯(¶ø²»ÊDz¢¼¯£¡)¼ÆËã¡££¨ÕâÑùÄã¿ÉÒÔÊÚÓèÔÚdb±íÌõÄ¿ÖеÄÒ»°ãȨÏÞ£¬È»ºóÓÃhost±íÌõÄ¿°´Ò»¸öÖ÷»úÒ»¸öÖ÷»úΪ»ù´¡µØÓÐÑ¡ÔñµØÏÞÖÆËüÃÇ¡££©
ÔÚÈ·¶¨ÁËÓÉdbºÍhost±íÌõÄ¿ÊÚÓèµÄÊý¾Ý¿âÌض¨µÄȨÏ޺󣬷þÎñÆ÷°ÑËûÃǼӵ½ÓÉuser±íÊÚÓèµÄÈ«¾ÖȨÏÞÖС£Èç¹û½á¹ûÔÊÐíÇëÇóµÄ²Ù×÷£¬´æÈ¡±»ÊÚȨ¡£·ñÔò£¬·þÎñÆ÷¼ì²éÔÚtables_privºÍcolumns_priv±íÖеÄÓû§µÄ±íºÍÁÐȨÏÞ²¢°ÑËüÃǼӵ½Óû§È¨ÏÞÖС£»ùÓڴ˽á¹ûÔÊÐí»ò¾Ü¾ø´æÈ¡¡£
Óò¼¶ûÊõÓï±íʾ£¬Ç°Ãæ¹ØÓÚÒ»¸öÓû§È¨ÏÞÈçºÎ¼ÆËãµÄÃèÊö¿ÉÒÔÕâÑù×ܽ᣺
global privileges OR (database privileges AND host privileges) OR table privileges OR column privileges
Ëü¿ÉÄܲ»Ã÷ÏÔ£¬ÎªÊ²Ã´ÄØ£¬Èç¹ûÈ«¾ÖuserÌõÄ¿µÄȨÏÞ×î³õ·¢ÏÖ¶ÔÇëÇóµÄ²Ù×÷²»¹»£¬·þÎñÆ÷ÒÔºó°ÑÕâЩȨÏÞ¼Óµ½Êý¾Ý¿â¡¢±íºÍÁеÄÌض¨È¨ÏÞ¡£ÔÒòÊÇÒ»¸öÇëÇó¿ÉÄÜÒªÇ󳬹ýÒ»ÖÖÀàÐ͵ÄȨÏÞ¡£ÀýÈ磬Èç¹ûÄãÖ´ÐÐÒ»¸öINSERT ... SELECTÓï¾ä£¬Äã¾Í¶¼ÒªinsertºÍselectȨÏÞ¡£ÄãµÄȨÏÞ±ØÐëÈç´ËÒÔ±ãuser±íÌõÄ¿ÊÚÓèÒ»¸öȨÏÞ¶ødb±íÌõÄ¿ÊÚÓèÁíÒ»¸ö¡£ÔÚÕâÖÖÇé¿öÏ£¬ÄãÓбØÒªµÄȨÏÞÖ´ÐÐÇëÇ󣬵«ÊÇ·þÎñÆ÷²»ÄÜ×Ô¼º°ÑÁ½¸ö±íÇø±ð¿ªÀ´£»Á½¸öÌõÄ¿ÊÚÓèµÄȨÏÞ±ØÐë×éºÏÆðÀ´¡£
host±íÄܱ»ÓÃÀ´Î¬»¤Ò»¸ö¡°°²È«¡±·þÎñÆ÷ÁÐ±í¡£ÔÚTcX£¬host±í°üº¬Ò»¸öÔÚ±¾µØµÄÍøÂçÉÏËùÓеĻúÆ÷µÄ±í£¬ÕâЩ±»ÊÚÓèËùÓеÄȨÏÞ¡£
ÄãÒ²¿ÉÒÔʹÓÃhost±íÖ¸¶¨²»°²È«µÄÖ÷»ú¡£¼Ù¶¨ÄãÓÐһ̨»úÆ÷public.your.domain£¬ËüλÓÚÄã²»ÈÏΪÊÇ°²È«µÄÒ»¸ö¹«¹²ÇøÓò£¬Äã¿ÉÒÔÓÃÏÂÁеÄhost±íÌõÄ¿×ÓÔÊÐí³ýÁËÄÇ̨»úÆ÷ÍâµÄÍøÂçÉÏËùÓÐÖ÷»úµÄ´æÈ¡£º
+--------------------+----+- | Host | Db | ... +--------------------+----+- | public.your.domain | % | ... (ËùÓÐȨÏÞÉèΪ 'N') | %.your.domain | % | ... (ËùÓÐȨÏÞÉèΪ 'Y') +--------------------+----+-
µ±È»£¬ÄãÓ¦¸Ã×ÜÊDzâÊÔÄãÔÚÊÚȨ±íÖеÄÌõÄ¿(ÀýÈ磬ʹÓÃmysqlaccess)ÈÃÄãÈ·±£ÄãµÄ´æȡȨÏÞʵ¼ÊÉÏÒÔÄãÈÏΪµÄ·½Ê½±»ÉèÖá£
6.9 ȨÏÞ¸ü¸ÄºÎʱÉúЧ µ±mysqldÆô¶¯Ê±£¬ËùÓеÄÊÚȨ±íÄÚÈݱ»¶Á½ø´æ´¢Æ÷²¢ÇÒ´ÓÄǵãÉúЧ¡£
ÓÃGRANT¡¢REVOKE»òSET PASSWORD¶ÔÊÚȨ±íÊ©ÐеÄÐ޸ĻáÁ¢¼´±»·þÎñÆ÷×¢Òâµ½¡£
Èç¹ûÄãÊÖ¹¤µØÐÞ¸ÄÊÚȨ±í(ʹÓÃINSERT¡¢UPDATEµÈµÈ)£¬ÄãÓ¦¸ÃÖ´ÐÐÒ»¸öFLUSH PRIVILEGESÓï¾ä»òÔËÐÐmysqladmin flush-privileges¸æËß·þÎñÆ÷ÔÙ×°ÔØÊÚȨ±í£¬·ñÔòÄãµÄ¸Ä±ä½«²»ÉúЧ£¬³ý·ÇÄãÖØÆô·þÎñÆ÷¡£
µ±·þÎñÆ÷×¢Òâµ½ÊÚȨ±í±»¸Ä±äÁËʱ£¬ÏÖ´æµÄ¿Í»§Á¬½ÓÓÐÈçÏÂÓ°Ï죺
- ±íºÍÁÐȨÏÞÔÚ¿Í»§µÄÏÂÒ»´ÎÇëÇóʱÉúЧ¡£
- Êý¾Ý¿âȨÏ޸ıäÔÚÏÂÒ»¸öUSE db_nameÃüÁîÉúЧ¡£
- È«¾ÖȨÏ޵ĸıäºÍ¿ÚÁî¸Ä±äÔÚÏÂÒ»´Î¿Í»§Á¬½ÓʱÉúЧ¡£
6.10 ½¨Á¢³õʼµÄMySQLȨÏÞ ÔÚ°²×°MySQLºó£¬Äãͨ¹ýÔËÐÐscripts/mysql_install_db°²×°³õʼµÄ´æȡȨÏÞ¡£¼û4.7.1 ¿ìËÙ°²×°¸ÅÊö¡£ scripts/mysql_install_db½Å±¾Æô¶¯mysqld·þÎñÆ÷£¬È»ºó³õʼ»¯ÊÚȨ±í£¬°üº¬ÏÂÁÐȨÏÞ¼¯ºÏ£º
- MySQL rootÓû§×÷Ϊ¿É×öÈκÎÊÂÇéµÄÒ»¸ö³¬¼¶Óû§±»´´Ôì¡£Á¬½Ó±ØÐëÓɱ¾µØÖ÷»ú·¢³ö¡£×¢Ò⣺³öÊÀµÄroot¿ÚÁîÊǿյģ¬Òò´ËÈκÎÈËÄÜÒÔroot¶øûÓÐÒ»¸ö¿ÚÁî½øÐÐÁ¬½Ó²¢ÇÒ±»ÊÚÓèËùÓÐȨÏÞ¡£
- Ò»¸öÄäÃûÓû§±»´´Ô죬Ëû¿É¶ÔÓÐÒ»¸ö'test'»òÒÔ'test_'¿ªÊ¼µÄÃû×ÖµÄÊý¾Ý¿â×öÈκÎʱÆÚÊÂÇ飬Á¬½Ó±ØÐëÓɱ¾µØÖ÷»ú·¢³ö¡£ÕâÒâζ×ÅÈκα¾µØÓû§ÄÜÁ¬½Ó²¢ÇÒÊÓΪÄäÃûÓû§¡£
- ÆäËûȨÏÞ±»¾Ü¾ø¡£ÀýÈ磬һ°ãÓû§²»ÄÜʹÓÃmysqladmin shutdown»òmysqladmin processlist¡£
×¢Ò⣺¶ÔWin32µÄ³õʼȨÏÞÊDz»Í¬µÄ¡£¼û4.12.4 ÔÚWin32ÉÏÔËÐÐMySQL¡£
¼ÈÈ»ÄãµÄ°²×°³õʼʱ¹ã¿ª´óÃÅ£¬ÄãÊ×ÏÈÓ¦¸Ã×öµÄÊÂÇéÖ®Ò»ÊÇΪMySQL rootÓû§Ö¸¶¨Ò»¸ö¿ÚÁî¡£Äã¿ÉÒÔ×öÈçÏÂ(×¢Ò⣬ÄãʹÓÃPASSWORD()º¯ÊýÖ¸¶¨¿ÚÁî)£º
shell> mysql -u root mysql mysql> UPDATE user SET Password=PASSWORD('new_password') WHERE user='root'; mysql> FLUSH PRIVILEGES;
ÔÚMySQL 3.22ºÍÒÔÉÏ°æ±¾ÖУ¬Äã¿ÉÒÔʹÓÃSET PASSWORDÓï¾ä£º
shell> mysql -u root mysql mysql> SET PASSWORD FOR root=PASSWORD('new_password');
ÉèÖÿÚÁîµÄÁíÒ»ÖÖ·½·¨ÊÇʹÓÃmysqladminÃüÁ
shell> mysqladmin -u root password new_password
×¢Ò⣺Èç¹ûÄãʹÓõÚÒ»ÖÖ·½·¨ÔÚuser±íÀïÖ±½Ó¸üпÚÁÄã±ØÐë¸æËß·þÎñÆ÷ÔٴζÁÈëÊÚȨ±í(ÓÃFLUSH PRIVILEGES)£¬ÒòΪ·ñÔò¸Ä±ä½«²»±»×¢Òâµ½¡£
Ò»µ©root¿ÚÁî±»ÉèÖ㬴˺óµ±Äã×÷ΪrootÓë·þÎñÆ÷Á¬½Óʱ£¬Äã±ØÐ빩ӦÄǸö¿ÚÁî¡£
Äã¿ÉÄÜÏ£ÍûÈÃroot¿ÚÁîΪ¿Õ°×ÒԱ㵱ÄãÊ©Ðи½¼ÓµÄ°²×°Ê±£¬Äã²»ÐèÒªÖ¸¶¨Ëü»ò²âÊÔ£¬µ«ÊDZ£Ö¤ÔÚÈκÎÕæʵµÄÉú²ú¹¤×÷ÖÐʹÓÃÄãµÄ°²×°Ö®Ç°£¬ÉèÖÃËü¡£
¿´¿´scripts/mysql_install_db½Å±¾£¬¿´ËüÈçºÎ°²×°È±Ê¡µÄȨÏÞ¡£Äã¿ÉÓÃËü×÷Ϊһ¸öÑо¿ÈçºÎÔö¼ÓÆäËûÓû§µÄ»ù´¡¡£
Èç¹ûÄãÏëÒª³õʼµÄȨÏÞ²»Í¬ÓÚÉÏÃæÃèÊöµÄÄÇЩ£¬ÔÚÄãÔËÐÐmysql_install_db֮ǰ£¬Äã¿ÉÒÔÐÞ¸ÄËü¡£
ΪÁËÍêÈ«Öؽ¨È¨ÏÞ±í£¬É¾³ýÔÚ°üº¬mysqlÊý¾Ý¿âµÄĿ¼ÏÂËùÓС°*.frm¡±,¡°*.MYI¡±ºÍ¡°*.MYD¡±Îļþ¡££¨ÕâÊÇÔÚÊý¾Ý¿âĿ¼ÏÂÃæÃüÃûΪ¡°mysql¡±µÄĿ¼£¬µ±ÄãÔËÐÐmysqld --helpʱ£¬Ëü±»Áгö¡£)È»ºóÔËÐÐmysql_install_db½Å±¾£¬¿ÉÄÜÔÚÊ×Ïȱà¼ËüÓµÓÐÄãÏëÒªµÄȨÏÞÖ®ºó¡£
×¢Ò⣺¶ÔÓÚ±ÈMySQL 3.22.10¾ÉµÄ°æ±¾£¬Äã²»Ó¦¸Ãɾ³ý¡°*.frm¡±Îļþ¡£Èç¹ûÄãżȻ×öÁË£¬ÄãÓ¦¸ÃÔÚÔËÐÐmysql_install_db֮ǰÄãµÄMySQL·Ö·¢Öп½»ØËüÃÇ¡£
6.11 ÏòMySQLÔö¼ÓÐÂÓû§È¨ÏÞ Äã¿ÉÒÔÓÐ2¸ö²»Í¬µÄ·½·¨Ôö¼ÓÓû§£ºÍ¨¹ýʹÓÃGRANTÓï¾ä»òͨ¹ýÖ±½Ó²Ù×÷MySQLÊÚȨ±í¡£±È½ÏºÃµÄ·½·¨ÊÇʹÓÃGRANTÓï¾ä£¬ÒòΪËûÃÇÊǸü¼òÃ÷²¢ÇÒºÃÏñ´íÎóÉÙЩ¡£
ÏÂÃæµÄÀý×ÓÏÔʾ³öÈçºÎʹÓÃmysql¿Í»§°²×°ÐÂÓû§¡£ÕâЩÀý×Ó¼Ù¶¨È¨ÏÞ¸ù¾ÝÒÔÇ°µÄÕ½ÚÃèÊöµÄȱʡ±»°²×°¡£ÕâÒâζ×ÅΪÁ˸ı䣬Äã±ØÐëÔÚmysqldÕýÔÚÔËÐÐͬһ̨»úÆ÷ÉÏ£¬Äã±ØÐë×÷ΪMySQL rootÓû§Á¬½Ó£¬²¢ÇÒrootÓû§±ØÐë¶ÔmysqlÊý¾Ý¿âÓÐinsertȨÏÞºÍreload¹ÜÀíȨÏÞ¡£ÁíÍ⣬Èç¹ûÄã¸Ä±äÁËrootÓû§¿ÚÁÄã±ØÐëÈçϵÄmysqlÃüÁîÖ¸¶¨Ëü¡£
Äã¿ÉÒÔͨ¹ý·¢³öGRANTÓï¾äÔö¼ÓÐÂÓû§£º
shell> mysql --user=root mysql mysql> GRANT ALL PRIVILEGES ON *.* TO monty@localhost IDENTIFIED BY 'something' WITH GRANT OPTION; mysql> GRANT ALL PRIVILEGES ON *.* TO monty@"%" IDENTIFIED BY 'something' WITH GRANT OPTION; mysql> GRANT RELOAD,PROCESS ON *.* TO admin@localhost; mysql> GRANT USAGE ON *.* TO dummy@localhost;
ÕâЩGRANTÓï¾ä°²×°3¸öÐÂÓû§£º
monty ¿ÉÒÔ´ÓÈκεط½Á¬½Ó·þÎñÆ÷µÄÒ»¸öÍêÈ«µÄ³¬¼¶Óû§£¬µ«ÊDZØÐëʹÓÃÒ»¸ö¿ÚÁî('something'×öÕâ¸ö¡£×¢Ò⣬ÎÒÃDZØÐë¶Ômonty@localhostºÍmonty@"%"·¢³öGRANTÓï¾ä¡£Èç¹ûÎÒÃÇÔö¼ÓlocalhostÌõÄ¿£¬¶ÔlocalhostµÄÄäÃûÓû§ÌõÄ¿ÔÚÎÒÃÇ´Ó±¾µØÖ÷»úÁ¬½Ó½ÓʱÓÉmysql_install_db´´½¨µÄÌõÄ¿½«ÓÅÏÈ¿¼ÂÇ£¬ÒòΪËüÓиüÌض¨µÄHost×Ö¶ÎÖµ£¬ËùÒÔÒÔuser±íÅÅÁÐ˳Ðò¿´¸üÔçµ½À´¡£ admin ¿ÉÒÔ´ÓlocalhostûÓÐÒ»¸ö¿ÚÁî½øÐÐÁ¬½Ó²¢ÇÒ±»ÊÚÓèreloadºÍprocess¹ÜÀíȨÏÞµÄÓû§¡£ÕâÔÊÐíÓû§Ö´ÐÐmysqladmin reload¡¢mysqladmin refreshºÍmysqladmin flush-*ÃüÁ»¹ÓÐmysqladmin processlist¡£Ã»ÓÐÊÚÓèÊý¾Ý¿âÓйصÄȨÏÞ¡£ËûÃÇÄÜÔÚÒÔºóͨ¹ý·¢³öÁíÒ»¸öGRANTÓï¾äÊÚȨ¡£ dummy ¿ÉÒÔ²»ÓÃÒ»¸ö¿ÚÁîÁ¬½ÓµÄÒ»¸öÓû§£¬µ«ÊÇÖ»ÄÜ´Ó±¾µØÖ÷»ú¡£È«¾ÖȨÏÞ±»ÉèÖÃΪ'N'--USAGEȨÏÞÀàÐÍÔÊÐíÄãÎÞÐèȨÏ޾ͿÉÉèÖÃÒ»¸öÓû§¡£Ëü¼Ù¶¨Ä㽫ÔÚÒÔºóÊÚÓèÊý¾Ý¿âÏà¹ØµÄȨÏÞ¡£ ÄãÒ²¿ÉÒÔÖ±½Óͨ¹ý·¢³öINSERTÓï¾äÔö¼ÓͬÑùµÄÓû§´æÈ¡ÐÅÏ¢£¬È»ºó¸æËß·þÎñÆ÷ÔÙ´Î×°ÈëÊÚȨ±í£º
shell> mysql --user=root mysql mysql> INSERT INTO user VALUES('localhost','monty',PASSWORD('something'), 'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y') mysql> INSERT INTO user VALUES('%','monty',PASSWORD('something'), 'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y') mysql> INSERT INTO user SET Host='localhost',User='admin', Reload_priv='Y', Process_priv='Y'; mysql> INSERT INTO user (Host,User,Password) VALUES('localhost','dummy',''); mysql> FLUSH PRIVILEGES;
È¡¾öÓÚÄãµÄMySQL°æ±¾£¬¶ÔÉÏÊö£¬Äã¿ÉÄܱØÐëʹÓÃÒ»¸ö²»Í¬ÊýÄ¿'Y'Öµ(ÔÚ3.22.11ÒÔÇ°µÄ°æ±¾ÓиüÉÙµÄȨÏÞÁÐ)¡£¶ÔadminÓû§£¬Ö»ÓÃÔÚ3.22.11¿ªÊ¼µÄ°æ±¾¾ßÓеĸü¼Ó¿É¶ÁµÄINSERTÀ©³äµÄÓï·¨¡£
×¢Ò⣬ΪÁËÉèÖÃÒ»¸ö³¬¼¶Óû§£¬ÄãÖ»Ðè´´ÔìÒ»¸öuser±íÌõÄ¿£¬ÆäȨÏÞ×Ö¶ÎÉèΪ'Y'¡£²»ÐèÒªdb»òhost±íµÄÌõÄ¿¡£
ÔÚuser±íÖеÄȨÏÞÁв»ÊÇÓÉ×îºóÒ»¸öINSERTÓï¾äÃ÷È·ÉèÖõÄ(¶ÔdummyÓû§)£¬Òò´ËÄÇЩÁб»¸³Óèȱʡֵ'N'¡£ÕâÊÇGRANT USAGE×öµÄͬÑùµÄÊÂÇé¡£
ÏÂÁÐÀý×ÓÔö¼ÓÒ»¸öÓû§custom£¬ËûÄÜ´ÓÖ÷»úlocalhost¡¢server.domainºÍwhitehouse.govÁ¬½Ó¡£ËûÖ»ÏëÒª´Ólocalhost´æÈ¡bankaccountÊý¾Ý¿â£¬´Ówhitehouse.gov´æÈ¡expensesÊý¾Ý¿âºÍ´ÓËùÓÐ3̨Ö÷»ú´æÈ¡customerÊý¾Ý¿â¡£ËûÏëÒª´ÓËùÓÐ3̨Ö÷»úÉÏʹÓÿÚÁîstupid¡£
ΪÁËʹÓÃGRANTÓï¾äÉèÖøöÓû§µÄȨÏÞ£¬ÔËÐÐÕâЩÃüÁ
shell> mysql --user=root mysql mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON bankaccount.* TO custom@localhost IDENTIFIED BY 'stupid'; mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON expenses.* TO custom@whitehouse.gov IDENTIFIED BY 'stupid'; mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON customer.* TO custom@'%' IDENTIFIED BY 'stupid';
ͨ¹ýÖ±½ÓÐÞ¸ÄÊÚȨ±íÉèÖÃÓû§È¨ÏÞ£¬ÔËÐÐÕâЩÃüÁî(×¢Ò⣬ÔÚ½áÊøʱFLUSH PRIVILEGES)£º
shell> mysql --user=root mysql mysql> INSERT INTO user (Host,User,Password) VALUES('localhost','custom',PASSWORD('stupid')); mysql> INSERT INTO user (Host,User,Password) VALUES('server.domain','custom',PASSWORD('stupid')); mysql> INSERT INTO user (Host,User,Password) VALUES('whitehouse.gov','custom',PASSWORD('stupid')); mysql> INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv, Create_priv,Drop_priv) VALUES ('localhost','bankaccount','custom','Y','Y','Y','Y','Y','Y'); mysql> INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv, Create_priv,Drop_priv) VALUES ('whitehouse.gov','expenses','custom','Y','Y','Y','Y','Y','Y'); mysql> INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv, Create_priv,Drop_priv) VALUES('%','customer','custom','Y','Y','Y','Y','Y','Y'); mysql> FLUSH PRIVILEGES;
Í·3¸öINSERTÓï¾äÔö¼Óuser±íÌõÄ¿£¬ÔÊÐíÓû§customÓøø¶¨¿ÚÁî´Ó²»Í¬µÄÖ÷»ú½øÐÐÁ¬½Ó£¬µ«ÊÇûÓÐÊÚÓèÈκÎÐí¿É(ËùÓÐȨÏÞ±»ÉèÖÃΪȱʡֵ'N')¡£ºó3¸öINSERTÓï¾äÔö¼Ódb±íÌõÄ¿£¬ÊÚÓècustomÒÔbankaccount¡¢expensesºÍcustomerÊý¾Ý¿âȨÏÞ£¬µ«ÊÇÖ»ÄÜÔÚ´ÓÕýÈ·µÄÖ÷»ú´æȡʱ¡£Í¨³££¬ÔÚÊÚȨ±íÖ±½Ó±»ÐÞ¸Äʱ£¬·þÎñÆ÷±ØÐë±»¸æÖªÔÙ´Î×°ÈëËûÃÇ(ÓÃFLUSH PRIVILEGES)ÒÔ±ãʹȨÏÞÐÞ¸ÄÉúЧ¡£
Èç¹ûÄãÏëÒª¸øÌض¨µÄÓû§´ÓÒ»¸ö¸ø¶¨µÄÓòÉϵÄÈκλúÆ÷ÉÏ´æȡȨÏÞ£¬Äã¿ÉÒÔ·¢³öÒ»¸öÈçϵÄGRANTÓï¾ä£º
mysql> GRANT ... ON *.* TO myusername@"%.mydomainname.com" IDENTIFIED BY 'mypassword';
ΪÁËͨ¹ýÖ±½ÓÐÞ¸ÄÊÚȨ±í×öͬÑùµÄÊÂÇ飬ÕâÑù×ö£º
mysql> INSERT INTO user VALUES ('%.mydomainname.com', 'myusername', PASSWORD('mypassword'),...); mysql> FLUSH PRIVILEGES;
ÄãÒ²¿ÉÒÔʹÓÃxmysqladmin¡¢mysql_webadminÉõÖÁxmysqlÔÚÊÚȨ±íÖвåÈë¡¢¸Ä±äºÍ¸üÐÂÖµ¡£Äã¿ÉÒÔÔÚMySQLµÄContribĿ¼ÕÒµ½ÕâЩʵÓóÌÐò¡£
6.12 ÔõÑùÉèÖÿÚÁî ÔÚÇ°ÃæС½ÚµÄÀý×ÓÀï˵Ã÷ÁËÒ»¸öÖØÒªµÄÔÔò£ºµ±ÄãʹÓÃINSERT»òUPDATEÓï¾ä´æ´¢Ò»¸ö·Ç¿ÕµÄ¿ÚÁîʱ£¬Äã±ØÐëʹÓÃPASSWORD()º¯Êý¼ÓÃÜËü¡£ÕâÊÇÒòΪÔÚuser±íÖÐÒÔ¼ÓÃÜÐÎʽ´æ´¢¿ÚÁ¶ø²»ÊÇ×÷Ϊ´¿Îı¾¡£Èç¹ûÄãÍü¼ÇÕâ¸öÊÂʵ£¬Äã¿ÉÄÜÏñÕâÑùÊÔͼÉèÖÿÚÁ
shell> mysql -u root mysql mysql> INSERT INTO user (Host,User,Password) VALUES('%','jeffrey','biscuit'); mysql> FLUSH PRIVILEGES
½á¹ûÊÇ´¿Îı¾Öµ'biscuit'×÷Ϊ¿ÚÁî±»´æ´¢ÔÚuser±íÖС£ÔÚÓû§jeffreyÊÔͼÓÃÕâ¸ö¿ÚÁîÁ¬½Ó·þÎñÆ÷ʱ£¬mysql¿Í»§ÓÃPASSWORD()¼ÓÃÜËü²¢ÇÒ½«½á¹ûË͸ø·þÎñÆ÷£¬·þÎñÆ÷±È½ÏÔÚuser±íÖеÄÖµ(ËüÊÇ´¿Îı¾Öµ'biscuit')ºÍ¼ÓÃܵĿÚÁî(¶ø²»ÊÇ 'biscuit')£¬±È½Ïʧ°Ü²¢ÇÒ·þÎñÆ÷¾Ü¾øÁ¬½Ó£º
shell> mysql -u jeffrey -pbiscuit test Access denied
ÒòΪµ±ËûÃDZ»²åÈëuser±íʱ£¬¿ÚÁî±ØÐë±»¼ÓÃÜ£¬Ïà·´£¬INSERTÓï¾äÓ¦¸ÃÏóÕâÑù±»Ö¸¶¨£º
mysql> INSERT INTO user (Host,User,Password) VALUES('%','jeffrey',PASSWORD('biscuit'));
µ±ÄãʹÓÃSET PASSWORDÓï¾äʱ£¬ÄãÒ²±ØÐëʹÓÃPASSWORD()º¯Êý£º
mysql> SET PASSWORD FOR jeffrey@"%" = PASSWORD('biscuit');
Èç¹ûÄãʹÓÃGRANT ... IDENTIFIED BYÓï¾ä»òmysqladmin passwordÃüÁîÉèÖÿÚÁPASSWORD()º¯ÊýÊDz»±ØÒªµÄ¡£ËûÃǶ¼¿¼Âǵ½ÎªÄã¼ÓÃÜ¿ÚÁ¶àÒÔÄã¿ÉÏñÕâÑùÖ¸¶¨Ò»¸ö¿ÚÁî'biscuit'£º
mysql> GRANT USAGE ON *.* TO jeffrey@"%" IDENTIFIED BY 'biscuit';
»ò
shell> mysqladmin -u jeffrey password biscuit
×¢Ò⣺ PASSWORD()²»ÊÇÒÔÔÚUnix¿ÚÁî¼ÓÃܵÄͬÑù·½·¨Ê©ÐпÚÁî¼ÓÃÜ¡£Äã²»Ó¦¸Ã¼Ù¶¨Èç¹ûÄãµÄUnix¿ÚÁîºÍÄãµÄMySQL¿ÚÁîÊÇÒ»ÑùµÄ£¬PASSWORD()½«µ¼ÖÂÓëÔÚUnix¿ÚÁîÎļþ±»´æ´¢µÄͬÑùµÄ¼ÓÃÜÖµ¡£¼û6.2 MySQL Óû§ÃûºÍ¿ÚÁî¡£
6.13 Access denied´íÎóµÄÔÒò
- µ±ÄãÊÔ×ÅÁª½ÓMySQL·þÎñÆ÷ʱ£¬Èç¹ûÄãÅöµ½Access denied´íÎó£¬ÏÔʾÔÚÏÂÃæµÄ±íÖ¸³öһЩÄãÄÜÓÃÀ´¸üÕýÕâ¸öÎÊÌâµÄ¶¯×÷£º
ÄãÊÇÔÚ°²×°MySQLÒÔºóÔËÐÐmysql_install_dbµÄ½Å±¾£¬À´ÉèÖóõʼÊÚȨ±íÄÚÈÝÂð£¿Èç¹û²»ÊÇ£¬ÕâÑù×ö¡£¼û6.10 ÉèÖóõʼMySQLȨÏÞ¡£Í¨¹ýÖ´ÐÐÕâ¸öÃüÁî²âÊÔ³õʼȨÏÞ£º shell> mysql -u root test
·þÎñÆ÷Ó¦¸ÃÈÃÄãÎÞÎóµØÁ¬½Ó¡£ÄãÒ²Ó¦¸Ã±£Ö¤ÄãÔÚMySQLÊý¾Ý¿âĿ¼ÓÐÒ»¸öÎļþ¡°user.MYD¡±¡£Í¨³££¬ËüÊÇ¡°PATH/var/mysql/user.MYD¡±£¬ÔÚ´ËPATHÊÇMySQL°²×°¸ùĿ¼µÄ·¾¶¡£
- ÔÚÒ»¸öÐµİ²×°ÒÔºó£¬ÄãÓ¦¸ÃÁ¬½Ó·þÎñÆ÷²¢ÇÒÉèÖÃÄãµÄÓû§¼°Æä´æÈ¡Ðí¿É£º
shell> mysql -u root mysql
·þÎñÆ÷Ó¦¸ÃÈÃÄãÁ¬½Ó£¬ÒòΪMySQL rootÓû§³õʼʱûÓпÚÁî¡£¼ÈÈ»ÄÇÒ²ÊÇÒ»¸ö°²È«·çÏÕ£¬µ±ÄãÕýÔÚÉèÖÃÆäËûMySQLÓû§Ê±£¬É趨root¿ÚÁîÊÇÒ»¼þÖØÒªµÄÊÂÇë¡£Èç¹ûÄã×÷Ϊroot³¢ÊÔÁ¬½Ó²¢Çҵõ½Õâ¸ö´íÎó£º
Access denied for user: '@unknown' to database mysql
ÕâÒâζ×Å£¬ÄãûÓÐÒ»¸öÌõÄ¿ÔÚuser±íÖеÄÒ»¸öUserÁÐֵΪ'root'²¢ÇÒmysqld²»ÄÜΪÄãµÄ¿Í¿â½âÎöÖ÷»úÃû¡£ÔÚÕâÖÖÇé¿öÏ£¬Äã±ØÐëÓÃ--skip-grant-tablesÑ¡ÏîÖØÆô·þÎñÆ÷²¢ÇÒ±à¼ÄãµÄ¡°/etc/hosts¡±»ò¡°windowshosts¡±ÎļþΪÄãµÄÖ÷»úÔö¼ÓÒ»¸öÌõÄ¿¡£
- Èç¹ûÄã´ÓÒ»¸ö3.22.11ÒÔÇ°µÄ°æ±¾¸üÐÂÒ»¸öÏÖ´æµÄMySQL°²×°µ½3.22.11°æ»òÒÔºó°æ±¾£¬ÄãÔËÐÐÁËmysql_fix_privilege_tables½Å±¾Âð£¿Èç¹ûûÓУ¬ÔËÐÐËü¡£ÔÚGRANTÓï¾ä±äµÃÄܹ¤×÷ʱ£¬ÊÚȨ±íµÄ½á¹¹ÓÃMySQL 3.22.11ÐÞ¸Ä ¡£
- Èç¹ûÄãÖ±½Ó¶ÔÊÚȨ±í×öÐÞ¸Ä(ʹÓÃINSERT»òUPDATEÓï¾ä)²¢ÇÒÄãµÄ¸Ä±äËƺõ±»ºöÂÔ£¬¼Çס£¬Äã±ØÐë·¢³öÒ»¸öFLUSH PRIVILEGESÓï¾ä»òÖ´ÐÐÒ»¸ömysqladmin flush-privilegesÃüÁîµ¼Ö·þÎñÆ÷ÔٴζÁÈë±í£¬·ñÔòÄãµÄ¸Ä±äÒªµÀÏÂÒ»´Î·þÎñÆ÷±»ÖØÆôʱÔÙÉúЧ¡£¼ÇסÔÚÄãÉ趨root¿ÚÁîÒÔºó£¬Ä㽫²»ÐèÒªÖ¸¶¨Ëü£¬Ö±µ½ÔÚÄãÇåÏ´(flush)ȨÏÞÒÔºó£¬ÒòΪ·þÎñÆ÷ÈÔÈ»²»»áÖªµÀÄã¸Ä±äÁË¿ÚÁ
- Èç¹ûÄãµÄȨÏÞËƺõÔÚÒ»¸ö»á»°(session)µ±ÖиıäÁË£¬¿ÉÄÜÊÇÒ»¸ö³¬¼¶Óû§¸Ä±äÁËËûÃÇ¡£ÔÙ´Î×°ÈëÊÚȨ±í×÷ÓÃÓÚпͻ§Á¬½Ó£¬µ«ÊÇËüÒ²Ó°ÏìÏÖ´æµÄÁ¬½Ó£¬Èç6.9 ȨÏ޸ıäºÎʱÉúЧС½ÚËùÊö¡£
- ΪÁ˲âÊÔ£¬ÓÃ--skip-grant-tablesÑ¡ÏîÆô¶¯mysqldÊØ»¤½ø³Ì£¬È»ºóÄã¿ÉÒԸıäMySQLÊÚȨ±í²¢ÇÒʹÓÃmysqlaccess½Å±¾¼ì²éÄãµÄÐÞ¸ÄÊÇ·ñÓÐÈçÆÚµÄЧ¹û¡£µ±Äã¶ÔÄãµÄ¸Ä±äÂúÒâʱ£¬Ö´ÐÐmysqladmin flush-privileges¸æËßmysqld·þÎñÆ÷¿ªÊ¼Ê¹ÓÃеÄȨÏÞ±í¡£×¢Ò⣺ÔÙ´Î×°ÈëÊÚȨ±í¸²¸ÇÁË--skip-grant-tablesÑ¡Ïî¡£ÕâÔÊÐíÄã¸æËß·þÎñÆ÷¿ªÊ¼Ê¹ÓÃÊÚȨ±í£¬¶ø²»ÓÃÍ£µô²¢ÖØÆôËü¡£
- Èç¹ûÄãÓÐÒ»¸öPerl¡¢Python»òODBC³ÌÐòµÄ´æÈ¡ÎÊÌ⣬ÊÔ×ÅÓÃmysql -u user_name db_name»òmysql -u user_name -pyour_pass db_nameÓë·þÎñÆ÷Á¬½Ó¡£Èç¹ûÄãÄÜÓÃmysql¿Í»§Á¬½Ó£¬ÕâÊÇÄã³ÌÐòµÄÒ»¸öÎÊÌâ¶ø²»ÊÇ´æȡȨÏÞµÄÎÊÌâ¡££¨×¢ÒâÔÚ-pºÍ¿ÚÁîÖ®¼äûÓпոñ£»ÄãÒ²ÄÜʹÓÃ--password=your_pass¾ä·¨Ö¸¶¨¿ÚÁî¡££©
- Èç¹ûÄã²»ÄÜÈÿÚÁ×÷£¬¼ÇµÃÈç¹ûÄãÓÃINSERT, UPDATE»òSET PASSWORDÓï¾äÉèÖÿÚÁÄã±ØÐëʹÓÃPASSWORD()º¯Êý¡£Èç¹ûÄãÓÃGRANT ... INDENTIFIED BYÓï¾ä»òmysqladmin passwordÃüÁîÖ¸¶¨¿ÚÁPASSWORD()º¯ÊýÊDz»ÐèÒªµÄ¡£¼û6.12 ÔõÑùÉèÖÿÚÁî¡£
- localhostÊÇÄã±¾µØÖ÷»úÃûµÄÒ»¸öͬÒå´Ê£¬²¢ÇÒÒ²ÊÇÈç¹ûÄã²»Ã÷È·µØÖ¸¶¨Ö÷»ú¶ø¿Í»§³¢ÊÔÁ¬½ÓµÄȱʡÖ÷»ú¡£È»¶ø£¬Èç¹ûÄãÕýÔÚÔËÐÐÓÚÒ»¸öʹÓÃMIT-pthreadsµÄϵͳÉÏ£¬Á¬½ÓlocalhostÊDz»ÐеÄ(localhostÁ¬½ÓʹÓÃUnixÌ×½Ó×Ö½øÐУ¬Ëüû±» MIT-pthreadsÖ§³Ö)£¬ÎªÁËÔÚÕâÑùµÄϵͳÉϱÜÃâÕâ¸öÎÊÌ⣬ÄãÓ¦¸ÃʹÓÃ--hostÑ¡ÏîÃ÷È·µØÃüÃû·þÎñÆ÷Ö÷»ú£¬Õ⽫×öÒ»¸ö TCP/IPÁ¬½Óµ½mysqld·þÎñÆ÷¡£ÔÚÕâÖÖÇé¿öÏ£¬Äã±ØÐëÓÐÔÚ·þÎñÆ÷Ö÷»úÉϵÄuser±íÖÐÌõÄ¿µÄÄãÕæʵµÄÖ÷»úÃû¡££¨¼´Ê¹ÄãÔÚ·þÎñÆ÷ͬһ̨µÄÖ÷»úÉÏÔËÐÐÒ»¸ö¿Í»§³ÌÐò£¬ÕâÒ²ÊÇÕæµÄ¡££©
- µ±³¢ÊÔÓÃmysql -u user_name db_nameÓëÊý¾Ý¿âÁ¬½Óʱ£¬Èç¹ûÄãµÃµ½Ò»¸öAccess denied´íÎó£¬Äã¿ÉÄÜÓÐÓëuser×ÀÓйصÄÎÊÌ⣬ͨ¹ýÖ´ÐÐmysql -u root mysql²¢ÇÒ·¢³öÏÂÃæµÄSQLÓï¾ä¼ì²é£º
mysql> SELECT * FROM user;
½á¹ûÓ¦¸Ã°üº¬Ò»¸öÓÐHostºÍUserÁеÄÌõÄ¿Æ¥ÅäÄãµÄ¼ÆËã»úÖ÷»úÃûºÍÄãµÄMySQLÓû§Ãû¡£
- Access denied´íÎóÏûÏ¢½«¸æËßÄ㣬ÄãÕýÔÚÓÃÄĸöÓû§³¢ÊԵǼ£¬ÄãÕýÔÚÊÔͼÓÃÁ¬½ÓÄĸöÖ÷»ú£¬²¢ÇÒÄãÊÇ·ñÕýÔÚʹÓÃÒ»¸ö¿ÚÁͨ³££¬ÄãÓ¦¸ÃÔÚuser±íÖÐÓÐÒ»¸öÌõÄ¿£¬ÕýÈ·µØÆ¥ÅäÔÚ´íÎóÏûÏ¢¸ø³öµÄÖ÷»úÃûºÍÓû§Ãû¡£
- Èç¹ûµ±ÄãÊÔ×Å´ÓÒ»¸ö²»ÊÇMySQL·þÎñÆ÷ÕýÔÚÔËÐеÄÖ÷»úÉÏÁ¬½Óʱ£¬ÄãµÃµ½ÏÂÁдíÎó£¬ÄÇôÔÚuser±íÖÐûÓÐÆ¥ÅäÄÇ̨Ö÷»úÐУº
Host ... is not allowed to connect to this MySQL server
Äã¿ÉÒÔͨ¹ýʹÓÃmysqlÃüÁîÐй¤¾ß£¨ÔÚ·þÎñÆ÷Ö÷»úÉÏ£¡)ÐÞÕýËü£¬°ÑÄãÕýÔÚÊÔͼÁ¬½ÓµÄÓû§/Ö÷»úÃû×éºÏмÓÒ»Ðе½user±íÖС£Èç¹ûÄã²»ÔÚÔËÐÐMySQL 3.22²¢ÇÒÄã²»ÖªµÀÄãÕýÔÚ´ÓËüÁ¬½ÓµÄ»úÆ÷µÄIPÊý×Ö»òÖ÷»úÃû£¬ÄãÓ¦¸Ã°ÑÒ»¸ö'%'ÌõÄ¿×÷ΪHostÁÐÖµ·ÅÔÚuser±íÖв¢ÇÒÔÚ·þÎñÆ÷»úÆ÷ÉÏʹÓÃ--logÑ¡ÏîÖØÆômysqld¡£ÔÚÊÔͼ´Ó¿Í»§»úÆ÷Á¬½ÓÒÔºó£¬ÔÚMySQL¼Ç¼ÎļþÖеÄÐÅÏ¢½«ÏÔʾÄãÈçºÎÕæÕý½øÐÐÁ¬½Ó¡££¨È»ºóÓÃÔڼǼÎļþÉÏÃæÏÔʾ³öµÄʵ¼ÊµÄÖ÷»úÃû´úÌæuser±íÖеÄ'%'ÌõÄ¿¡£·ñÔò£¬Ä㽫ÓÐÒ»¸ö²»°²È«µÄϵͳ¡££©
- Èç¹ûmysql -u root test¹¤×÷µ«ÊÇmysql -h your_hostname -u root testµ¼ÖÂAccess denied£¬ÄÇôÔÚuser±íÖÐÄã¿ÉÄÜûÓÐÄãµÄÖ÷»úµÄÕýÈ·Ãû×Ö¡£ÕâÀïµÄÒ»¸öÆÕ±éµÄÎÊÌâÊÇÔÚuser±íÌõÄ¿ÖеÄHostÖµÖ¸¶¨Ò»¸öΨһµÄÖ÷»úÃû£¬µ«ÊÇÄãϵͳµÄÃû×Ö½âÎöÀý³Ì·µ»ØÒ»¸öÍêÈ«Õý¹æµÄÓòÃû(»òÏà·´)¡£ÀýÈ磬Èç¹ûÄãÔÚuser±íÖÐÓÐÒ»¸öÖ÷»úÊÇ'tcx'µÄÌõÄ¿£¬µ«ÊÇÄãµÄ DNS¸æËßMySQLÄãµÄÖ÷»úÃûÊÇ'tcx.subnet.se'£¬ÌõÄ¿½«²»¹¤×÷¡£³¢ÊÔ°ÑÒ»¸öÌõÄ¿¼Óµ½user±íÖУ¬Ëü°üº¬ÄãÖ÷»úµÄIPÊý×Ö×÷ΪHostÁеÄÖµ¡££¨ÁíÍ⣬Äã¿ÉÒÔ°ÑÒ»¸öÌõÄ¿¼Óµ½user±íÖУ¬ËüÓаüº¬Ò»¸öͨÅä·ûÈç'tcx.%'µÄHostÖµ¡£È»¶ø£¬Ê¹ÓÃÒÔ¡°%¡±½áβµÄÖ÷»úÃûÊDz»°²È«µÄ²¢ÇÒ²»ÍƼö£¡£©
- Èç¹ûmysql -u user_name test¹¤×÷µ«ÊÇmysql -u user_name other_db_name²»¹¤×÷£¬¶Ôother_db_name£¬ÄãÔÚdb±íÖÐûÓÐûÓÐÒ»¸öÌõÄ¿Áгö¡£
- µ±ÔÚ·þÎñÆ÷»úÆ÷ÉÏÖ´ÐÐmysql -u user_name db_nameʱ£¬Ëü¹¤×÷£¬µ«ÊÇÔÚÆäËü¿Í»§»úÆ÷ÉÏÖ´ÐÐmysql -h host_name -u user_name db_nameʱ£¬ËüÈ´²»¹¤×÷£¬ÄãûÓаѿͻ§»úÆ÷ÁÐÔÚuser±í»òdb±íÖС£
- Èç¹ûÄã²»ÄÜŪÃ÷°×ÄãΪʲôµÃµ½Access denied£¬´Óuser±íÖÐɾ³ýËùÓÐHost°üº¬Í¨Åä·ûÖµµÄÌõÄ¿(°üº¬¡°%¡±»ò¡°_¡±µÄÌõÄ¿)¡£Ò»¸öºÜÆÕ±éµÄ´íÎóÊDzåÈëÓ**ost='%'ºÍUser='some user'²åÈëÒ»¸öÐÂÌõÄ¿£¬ÈÏΪÕ⽫ÔÊÐíÄãÖ¸¶¨localhost´Óͬһ̨»úÆ÷½øÐÐÁ¬½Ó¡£Ëü²»¹¤×÷µÄÔÒòÊÇȱʡȨÏÞ°üÀ¨Ò»¸öÓÐHost='localhost'ºÍUser=''µÄÌõÄ¿£¬ÒòΪÄǸöÌõÄ¿Ò»¸ö±È'%'¸ü¾ßÌåµÄHostÖµ'localhost'£¬µ±´ÓlocalhostÁ¬½Óʱ£¬ËüÓÃÓÚÖ¸ÏòÐÂÌõÄ¿£¡ÕýÈ·µÄ²½ÖèÊDzåÈëHost='localhost'ºÍUser='some_user'µÄµÚ2¸öÌõÄ¿£¬»òɾ³ýHost='localhost'ºÍUser=''ÌõÄ¿¡£
- Èç¹ûÄãµÃµ½ÏÂÁдíÎó£¬Äã¿ÉÒÔÓÐÒ»¸öÓëdb»òhost±íÓйصÄÎÊÌ⣺
Access to database denied
- Èç¹û´Ódb±íÖÐÑ¡ÔñÁËÔÚHostÁÐÓпÕÖµµÄÌõÄ¿£¬±£Ö¤ÔÚhost±íÖÐÓÐÒ»¸ö»ò¶à¸öÏàÓ¦µÄÌõÄ¿£¬Ö¸¶¨ÔËÓÃdb±íÖеÄÄÄЩÖ÷»ú¡£Èç¹ûÔÚʹÓÃSQLÃüÁîSELECT ... INTO OUTFILE»òLOAD DATA INFILEʱ£¬ÄãµÃµ½´íÎó£¬ÔÚuser±íÖеÄÄãµÄÌõÄ¿¿ÉÄÜÆôÓÃfileȨÏÞ¡£
- ¼Çס£¬¿Í»§³ÌÐò½«Ê¹ÓÃÔÚÅäÖÃÎļþ»ò»·¾³±äÁ¿±»Ö¸¶¨Á˵ÄÁ¬½Ó²ÎÊý¡£Èç¹ûµ±Äã²»ÔÚÃüÁîÐÐÉÏÖ¸¶¨ËûÃÇʱ£¬Ò»¸ö¿Í»§ËƺõÕýÔÚ·¢ËÍ´íÎóµÄȱʡÁ¬½Ó²ÎÊý£¬¼ì²éÄãµÄ»·¾³ºÍÔÚÄãµÄÖ÷Ŀ¼Ïµġ°.my.cnf¡±Îļþ¡£ÄãÒ²¿ÉÒÔ¼ì²éϵͳ·¶Î§µÄMySQLÅäÖÃÎļþ£¬¾¡¹Ü¸ü²»¿ÉÄܽ«ÔÚÄÇÀïÖ¸¶¨ÄǸö¿Í»§µÄÁ¬½Ó²ÎÊý¡£¼û4.15.4 Ñ¡ÏîÎļþ¡£Èç¹ûµ±ÄãûÓÐÈκÎÑ¡ÏîÔËÐÐÒ»¸ö¿Í»§Ê±£¬ÄãµÃµ½Access denied£¬È·ÈÏÄãûÔÚÈκÎÑ¡ÏîÎļþÀïÖ¸¶¨Ò»¸ö¾ÉµÄ¿ÚÁ¼û4.15.4 Ñ¡ÏîÎļþ¡£
- Èç¹ûÈκÎÆäËüÊÂÇéʧ°Ü£¬Óõ÷ÊÔÑ¡Ïî(ÀýÈ磬--debug=d,general,query)Æô¶¯mysqldÊØ»¤½ø³Ì¡£Õ⽫´òÓ¡Óйس¢ÊÔÁ¬½ÓµÄÖ÷»úºÍÓû§ÐÅÏ¢£¬ºÍ·¢³öµÄÿ¸öÃüÁîµÄÐÅÏ¢¡£¼ûG.1 µ÷ÊÔÒ»¸öMySQL·þÎñÆ÷¡£
- Èç¹ûÄãÓÐÈκÎÓëMySQLÊÚȨ±íµÄÆäËüÎÊÌ⣬¶øÇÒ¾õµÃÄã±ØÐëÓʼÄÕâ¸öÎÊÌâµ½ÓÊ¼Ä±í£¬×ÜÊÇÌṩһ¸öMySQLÊÚȨ±íµÄÇãµ¹¸±±¾(dump)¡£Äã¿ÉÓÃmysqldump mysqlÃüÁîÇãµ¹Êý¾Ý¿â±í¡£ÏóƽʱһÑù£¬ÓÃmysqlbug½Å±¾ÓʼÄÄãµÄÎÊÌâ¡£ÔÚһЩÇé¿öÏÂÄã¿ÉÄÜÓÃ--skip-grant-tablesÖØÆômysqldÒÔ±ãÄÜÔËÐÐmysqldump¡£
6.14 ÔõÑùʹMySQL°²È«ÒÔ¶Ô¿¹½âÃܸßÊÖ µ±ÄãÁ¬½ÓÒ»¸öMySQL·þÎñÆ÷ʱ£¬Äãͨ³£Ó¦¸ÃʹÓÃÒ»¸ö¿ÚÁî¡£¿ÚÁî²»ÒÔÃ÷ÎÄÔÚÁ¬½ÓÉÏ´«Êä¡£
ËùÓÐÆäËüÐÅÏ¢×÷ΪÄܱ»ÈκÎÈ˶Á¶®µÄÎı¾±»´«Êä¡£Èç¹ûÄãµ£ÐÄÕâ¸ö£¬Äã¿ÉʹÓÃѹËõÐÒé(MySQL3.22ºÍÒÔÉÏ°æ±¾)ʹÊÂÇé±äµÃ¸üÄÑ¡£ÉõÖÁΪÁËʹһÇиü°²È«£¬ÄãÓ¦¸Ã°²×°ssh£¨¼ûhttp://www.cs.hut.fi/ssh)¡£ÓÃËü£¬ÄãÄÜÔÚÒ»¸öMySQL·þÎñÆ÷ÓëÒ»¸öMySQL¿Í»§Ö®¼äµÃµ½Ò»¸ö¼ÓÃܵÄTCP/IPÁ¬½Ó¡£
ΪÁËʹһ¸öMySQLϵͳ°²È«£¬Ç¿ÁÒÒªÇóÄ㿼ÂÇÏÂÁн¨Ò飺
- ¶ÔËùÓÐMySQLÓû§Ê¹ÓÿÚÁî¡£¼Çס£¬Èç¹ûother_userûÓпÚÁÈκÎÈËÄܼòµ¥µØÓÃmysql -u other_user db_name×÷ΪÈκÎÆäËüµÄÈ˵Ǽ¡£¶Ô¿Í»§»ú/·þÎñÆ÷Ó¦ÓóÌÐò£¬¿Í»§¿ÉÒÔÖ¸¶¨ÈκÎÓû§ÃûÊdz£¼ûµÄ×ö·¨¡£ÔÚÄãÔËÐÐËüÒÔÇ°£¬Äã¿ÉÒÔͨ¹ý±à¼mysql_install_db½Å±¾¸Ä±äËùÓÐÓû§µÄ¿ÚÁ»ò½ö½öMySQL rootµÄ¿ÚÁÏóÕâÑù£º
shell> mysql -u root mysql mysql> UPDATE user SET Password=PASSWORD('new_password') WHERE user='root'; mysql> FLUSH PRIVILEGES;
- ²»Òª×÷ΪUnixµÄrootÓû§ÔËÐÐMySQLÊØ»¤½ø³Ì¡£mysqldÄÜÒÔÈκÎÓû§ÔËÐУ¬ÄãÒ²¿ÉÒÔ´´ÔìÒ»¸öеÄUnixÓû§mysqlʹһÇиü°²È«¡£Èç¹ûÄã×÷ΪÆäËüUnixÓû§ÔËÐÐmysqld£¬Äã²»ÐèÒª¸Ä±äÔÚuser±íÖеÄrootÓû§Ãû£¬ÒòΪMySQLÓû§ÃûÓëUnix Óû§Ãûû¹Øϵ¡£Äã¿ÉÒÔ×÷ΪÆäËüUnixÓû§±à¼mysql.serverÆô¶¯½Å±¾mysqld¡£Í¨³£ÕâÓÃsuÃüÁîÍê³É¡£¶ÔÓÚ¸ü¶àµÄϸ½Ú£¬¼û18.8 ÔõÑù×÷Ϊһ¸öÒ»°ãÓû§ÔËÐÐMySQL¡£
- Èç¹ûÄã°ÑÒ»¸öUnix rootÓû§¿ÚÁî·ÅÔÚmysql.server½Å±¾ÖУ¬È·±£Õâ¸ö½Å±¾Ö»ÄܶÔrootÊǿɶÁµÄ¡£
- ¼ì²éÄǸöÔËÐÐmysqldµÄUnixÓû§ÊÇΨһµÄÔÚÊý¾Ý¿âĿ¼ÏÂÓжÁ/дȨÏÞµÄÓû§¡£
- ²»Òª°ÑprocessȨÏÞ¸øËùÓÐÓû§¡£mysqladmin processlistµÄÊä³öÏÔʾ³öµ±Ç°Ö´ÐеIJéѯÕýÎÄ£¬Èç¹ûÁíÍâµÄÓû§·¢³öÒ»¸öUPDATE user SET password=PASSWORD('not_secure')²éѯ£¬±»ÔÊÐíÖ´ÐÐÄǸöÃüÁîµÄÈκÎÓû§¿ÉÄÜ¿´µÃµ½¡£mysqldΪÓÐprocessȨÏÞµÄÓû§±£ÁôÒ»¸ö¶îÍâµÄÁ¬½Ó, ÒÔ±ãÒ»¸öMySQL rootÓû§ÄܵǼ²¢¼ì²é£¬¼´Ê¹ËùÓеÄÕý³£Á¬½ÓÔÚʹÓá£
- ²»Òª°ÑfileȨÏÞ¸øËùÓеÄÓû§¡£ÓÐÕâȨÏÞµÄÈκÎÓû§ÄÜÔÚÓµÓÐmysqldÊØ»¤½ø³ÌȨÏÞµÄÎļþϵͳÄÇÀïдһ¸öÎļþ£¡ÎªÁËʹÕâ¸ü°²È«Ò»Ð©£¬ÓÃSELECT ... INTO OUTFILEÉú³ÉµÄËùÓÐÎļþ¶Ôÿ¸öÈËÊǿɶÁµÄ£¬²¢ÇÒÄã²»Äܸ²¸ÇÒѾ´æÔÚµÄÎļþ¡£fileȨÏÞÒ²¿ÉÒÔ±»ÓÃÀ´¶ÁÈ¡ÈκÎ×÷ΪÔËÐзþÎñÆ÷µÄUnixÓû§¿É´æÈ¡µÄÎļþ¡£Õâ¿ÉÄܱ»ÀÄÓã¬ÀýÈ磬ͨ¹ýʹÓÃLOAD DATA×°ÔØ¡°/etc/passwd¡±½øÒ»¸öÊý¾Ý¿â±í£¬È»ºóËüÄÜÓÃSELECT±»¶ÁÈë¡£
- Èç¹ûÄã²»ÐÅÈÎÄãµÄDNS£¬ÄãÓ¦¸ÃÔÚÊÚȨ±íÖÐʹÓÃIPÊý×Ö¶ø²»ÊÇÖ÷»úÃû¡£ÔÔòÉϽ²£¬--secureÑ¡Ïî¶ÔmysqldÓ¦¸ÃʹÖ÷»úÃû¸ü°²È«¡£ÔÚÈκÎÇé¿öÏ£¬ÄãÓ¦¸Ã·Ç³£Ð¡ÐĵØʹÓðüº¬Í¨Åä·ûµÄÖ÷»úÃû£¡
ÏÂÁÐmysqldÑ¡ÏîÓ°Ï찲ȫ£º
--secure ÓÉgethostbyname()ϵͳµ÷Ó÷µ»ØµÄIPÊý×Ö±»¼ì²é£¬È·±£ËûÃǽâÎö»Øµ½ÔÀ´µÄÖ÷»úÃû¡£Õâ¶ÔijЩÍâÈËͨ¹ýÄ£·ÂÆäËüÖ÷»ú»ñµÃ´æȡȨÏÞ±äµÃ¸üÄÑ¡£Õâ¸öÑ¡ÏîÒ²Ôö¼ÓһЩ´ÏÃ÷µÄÖ÷»úÃû¼ì²é¡£ÔÚMySQL3.21ÀѡÔñȱʡÊǹصôµÄ£¬ÒòΪËüÓÐʱËü»¨ºÜ³¤Ê±¼äÖ´Ðз´Ïò½âÎö¡£MySQL 3.22»º´æÖ÷»úÃû²¢È±Ê¡µØÆôÓÃÁËÕâ¸öÑ¡Ïî¡£ --skip-grant-tables Õâ¸öÑ¡Ïîµ¼Ö·þÎñÆ÷¸ù±¾²»Ê¹ÓÃȨÏÞϵͳ¡£Õâ¸øÿ¸öÈËÒÔÍêÈ«´æÈ¡ËùÓеÄÊý¾Ý¿âµÄȨÁ¦£¡£¨Í¨¹ýÖ´ÐÐmysqladmin reload£¬ÄãÄܸæËßÒ»¸öÕýÔÚÔËÐеķþÎñÆ÷ÔٴοªÊ¼Ê¹ÓÃÊÚȨ±í¡£) --skip-name-resolve Ö÷»úÃû²»±»½âÎö¡£ËùÓÐÔÚÊÚȨ±íµÄHostµÄÁÐÖµ±ØÐëÊÇIPÊý×Ö»òlocalhost¡£ --skip-networking ÔÚÍøÂçÉϲ»ÔÊÐíTCP/IPÁ¬½Ó¡£ËùÓе½mysqldµÄÁ¬½Ó±ØÐë¾ÓÉUnixÌ×½Ó×Ö½øÐС£Õâ¸öÑ¡Ïî¶ÔʹÓÃMIT-pthreadsµÄϵͳÊDz»ºÏÊʵģ¬ÒòΪMIT-pthreads°ü²»Ö§³ÖUnixÌ×½Ó×Ö¡£
ÔðÈα༣ºeight(2001-06-07 09:40) |
|
|
Ïà¹ØÎÄÕ£ºÏà¹ØÈí¼þ£º |
|