MysqlËø±í»úÖÆ,Êý¾Ý¿â¸ºÔØѹÁ¦²àÃæ½âÎö
ΪÁ˸ø¸ß²¢·¢Çé¿öϵÄmysql½øÐиüºÃµÄÓÅ»¯£¬ÓбØÒªÁ˽âÒ»ÏÂmysql²éѯ¸üÐÂʱµÄËø±í»úÖÆ¡£
Ò»¡¢¸ÅÊö
MySQLÓÐÈýÖÖËøµÄ¼¶±ð£ºÒ³¼¶¡¢±í¼¶¡¢Ðм¶¡£
MyISAMºÍMEMORY´æ´¢ÒýÇæ²ÉÓõÄÊÇ±í¼¶Ëø£¨table-level
locking£©£»BDB´æ´¢ÒýÇæ²ÉÓõÄÊÇÒ³ÃæËø£¨page-level
locking£©£¬µ«Ò²Ö§³Ö±í¼¶Ëø£»InnoDB´æ´¢ÒýÇæ¼ÈÖ§³ÖÐм¶Ëø£¨row-level
locking£©£¬Ò²Ö§³Ö±í¼¶Ëø£¬µ«Ä¬ÈÏÇé¿öÏÂÊDzÉÓÃÐм¶Ëø¡£
MySQLÕâ3ÖÖËøµÄÌØÐÔ¿É´óÖ¹éÄÉÈçÏ£º
±í¼¶Ëø£º¿ªÏúС£¬¼ÓËø¿ì£»²»»á³öÏÖËÀËø£»Ëø¶¨Á£¶È´ó£¬·¢ÉúËø³åÍ»µÄ¸ÅÂÊ×î¸ß,²¢·¢¶È×îµÍ¡£
Ðм¶Ëø£º¿ªÏú´ó£¬¼ÓËøÂý£»»á³öÏÖËÀËø£»Ëø¶¨Á£¶È×îС£¬·¢ÉúËø³åÍ»µÄ¸ÅÂÊ×îµÍ,²¢·¢¶ÈÒ²×î¸ß¡£
Ò³ÃæËø£º¿ªÏúºÍ¼ÓËøʱ¼ä½çÓÚ±íËøºÍÐÐËøÖ®¼ä£»»á³öÏÖËÀËø£»Ëø¶¨Á£¶È½çÓÚ±íËøºÍÐÐËøÖ®¼ä£¬²¢·¢¶ÈÒ»°ã¡£
¶þ¡¢MyISAM±íËø
MyISAM´æ´¢ÒýÇæÖ»Ö§³Ö±íËø£¬ÊÇÏÖÔÚÓõÃ×î¶àµÄ´æ´¢ÒýÇæ¡£
1¡¢²éѯ±í¼¶ËøÕùÓÃÇé¿ö
¿ÉÒÔͨ¹ý¼ì²étable_locks_waitedºÍtable_locks_immediate״̬±äÁ¿À´·ÖÎöϵͳÉϵıíËø¶¨Õù¶á£º
mysql>
show status like ¡®table%¡¯;
+¡ª¡ª¡ª¡ª¡ª¡ª¡ª¨C+¡ª¡ª¡ª-+
| Variable_name | Value
|
+¡ª¡ª¡ª¡ª¡ª¡ª¡ª¨C+¡ª¡ª¡ª-+
| Table_locks_immediate | 76939364 |
|
Table_locks_waited | 305089 |
+¡ª¡ª¡ª¡ª¡ª¡ª¡ª¨C+¡ª¡ª¡ª-+
2 rows in set (0.00
sec)Table_locks_waitedµÄÖµ±È½Ï¸ß£¬ËµÃ÷´æÔÚ׎ÏÑÏÖØµÄ±í¼¶ËøÕùÓÃÇé¿ö¡£
2¡¢MySQL±í¼¶ËøµÄËøģʽ
MySQLµÄ±í¼¶ËøÓÐÁ½ÖÖģʽ£º±í¹²Ïí¶ÁËø£¨Table Read
Lock£©ºÍ±í¶ÀռдËø£¨Table
Write
Lock£©¡£MyISAMÔÚÖ´ÐвéѯÓï¾ä£¨SELECT£©Ç°£¬»á×Ô¶¯¸øÉæ¼°µÄËùÓбí¼Ó¶ÁËø£¬ÔÚÖ´ÐиüвÙ×÷£¨UPDATE¡¢DELETE¡¢INSERTµÈ£©Ç°£¬»á×Ô¶¯¸øÉæ¼°µÄ±í¼ÓдËø¡£
ËùÒÔ¶ÔMyISAM±í½øÐвÙ×÷£¬»áÓÐÒÔÏÂÇé¿ö£º
a¡¢¶ÔMyISAM±íµÄ¶Á²Ù×÷£¨¼Ó¶ÁËø£©£¬²»»á×èÈûÆäËû½ø³Ì¶Ôͬһ±íµÄ¶ÁÇëÇ󣬵«»á×èÈû¶Ôͬһ±íµÄдÇëÇó¡£Ö»Ó屶ÁËøÊͷź󣬲ŻáÖ´ÐÐÆäËü½ø³ÌµÄд²Ù×÷¡£
b¡¢¶ÔMyISAM±íµÄд²Ù×÷£¨¼ÓдËø£©£¬»á×èÈûÆäËû½ø³Ì¶Ôͬһ±íµÄ¶ÁºÍд²Ù×÷£¬Ö»Óе±Ð´ËøÊͷź󣬲ŻáÖ´ÐÐÆäËü½ø³ÌµÄ¶Áд²Ù×÷¡£
ÏÂÃæͨ¹ýÀý×ÓÀ´½øÐÐÑéÖ¤ÒÔÉϹ۵㡣Êý¾Ý±ígz_phoneÀïÓжþ°Ù¶àÍòÊý¾Ý£¬×Ö¶Îid,phone,ua,day¡£ÏÖÔÚͬʱÓöà¸ö¿Í»§¶Ëͬʱ¶Ô¸Ã±í½øÐвÙ×÷·ÖÎö¡£
a¡¢µ±ÎÒÓÿͻ§¶Ë1½øÐÐÒ»¸ö±È½Ï³¤Ê±¼äµÄ¶Á²Ù×÷ʱ£¬·Ö±ðÓÿͻ§¶Ë2½øÐжÁºÍд²Ù×÷£º
client1:
mysql>select
count(*) from gz_phone group by ua;
75508 rows in set (3 min 15.87 sec)
client2:
select id,phone from gz_phone limit 1000,10;
+¡ª¡ª+¡ª¡ª-+
| id |
phone |
+¡ª¡ª+¡ª¡ª-+
| 1001 | 2222 |
| 1002 | 2222 |
| 1003 | 2222
|
| 1004 | 2222 |
| 1005 | 2222 |
| 1006 | 2222 |
| 1007 | 2222
|
| 1008 | 2222 |
| 1009 | 2222 |
| 1010 | 2222 |
+¡ª¡ª+¡ª¡ª-+
10
rows in set (0.01 sec)
mysql> update gz_phone set phone=¡¯11111111111¡ä
where id=1001;
Query OK, 0 rows affected (2 min 57.88 sec)
Rows matched: 1
Changed: 0 Warnings:
0
˵Ã÷µ±Êý¾Ý±íÓÐÒ»¸ö¶ÁËøʱ£¬ÆäËü½ø³ÌµÄ²éѯ²Ù×÷¿ÉÒÔÂíÉÏÖ´ÐУ¬µ«¸üвÙ×÷ÐèµÈ´ý¶ÁËøÊͷźó²Å»áÖ´ÐС£
b¡¢µ±Óÿͻ§¶Ë1½øÐÐÒ»¸ö½Ï³¤Ê±¼äµÄ¸üвÙ×÷ʱ£¬Óÿͻ§¶Ë2,3·Ö±ð½øÐжÁд²Ù×÷£º
client1:
mysql>
update gz_phone set phone=¡¯11111111111¡ä;
Query OK, 1671823 rows affected (3
min 4.03 sec)
Rows matched: 2212070 Changed: 1671823 Warnings: 0
client2:
mysql> select id,phone,ua,day from gz_phone limit
10;
+¡ª-+¡ª¡ª-+¡ª¡ª¡ª¡ª¡ª¡ª-+¡ª¡ª¡ª¡ª+
| id | phone | ua | day
|
+¡ª-+¡ª¡ª-+¡ª¡ª¡ª¡ª¡ª¡ª-+¡ª¡ª¡ª¡ª+
| 1 | 2222 | SonyEricssonK310c | 2007-12-19 |
|
2 | 2222 | SonyEricssonK750c | 2007-12-19 |
| 3 | 2222 | MAUI WAP Browser |
2007-12-19 |
| 4 | 2222 | Nokia3108 | 2007-12-19 |
| 5 | 2222 |
LENOVO-I750 | 2007-12-19 |
| 6 | 2222 | BIRD_D636 | 2007-12-19 |
| 7 |
2222 | SonyEricssonS500c | 2007-12-19 |
| 8 | 2222 | SAMSUNG-SGH-E258 |
2007-12-19 |
| 9 | 2222 | NokiaN73-1 | 2007-12-19 |
| 10 | 2222 |
Nokia2610 | 2007-12-19 |
+¡ª-+¡ª¡ª-+¡ª¡ª¡ª¡ª¡ª¡ª-+¡ª¡ª¡ª¡ª+
10 rows in set (2 min 58.56
sec) client3:
mysql> update gz_phone set phone=¡¯55555¡ä where
id=1;
Query OK, 1 row affected (3 min 50.16 sec)
Rows matched: 1 Changed:
1 Warnings: 0
˵Ã÷µ±Êý¾Ý±íÓÐÒ»¸öдËøʱ£¬ÆäËü½ø³ÌµÄ¶Áд²Ù×÷¶¼ÐèµÈ´ý¶ÁËøÊͷźó²Å»áÖ´ÐС£
3¡¢²¢·¢²åÈë
ÔÔòÉÏÊý¾Ý±íÓÐÒ»¸ö¶ÁËøʱ£¬ÆäËü½ø³ÌÎÞ·¨¶Ô´Ë±í½øÐиüвÙ×÷£¬µ«ÔÚÒ»¶¨Ìõ¼þÏ£¬MyISAM±íÒ²Ö§³Ö²éѯºÍ²åÈë²Ù×÷µÄ²¢·¢½øÐС£
MyISAM´æ´¢ÒýÇæÓÐÒ»¸öϵͳ±äÁ¿concurrent_insert£¬×¨ÃÅÓÃÒÔ¿ØÖÆÆä²¢·¢²åÈëµÄÐÐΪ£¬ÆäÖµ·Ö±ð¿ÉÒÔΪ0¡¢1»ò2¡£
a¡¢µ±concurrent_insertÉèÖÃΪ0ʱ£¬²»ÔÊÐí²¢·¢²åÈë¡£
b¡¢µ±concurrent_insertÉèÖÃΪ1ʱ£¬Èç¹ûMyISAM±íÖÐûÓпն´£¨¼´±íµÄÖмäûÓб»É¾³ýµÄÐУ©£¬MyISAMÔÊÐíÔÚÒ»¸ö½ø³Ì¶Á±íµÄͬʱ£¬ÁíÒ»¸ö½ø³Ì´Ó±íβ²åÈë¼Ç¼¡£ÕâÒ²ÊÇMySQLµÄĬÈÏÉèÖá£
c¡¢µ±concurrent_insertÉèÖÃΪ2ʱ£¬ÎÞÂÛMyISAM±íÖÐÓÐûÓпն´£¬¶¼ÔÊÐíÔÚ±íβ²¢·¢²åÈë¼Ç¼¡£
4¡¢MyISAMµÄËøµ÷¶È
ÓÉÓÚMySQLÈÏΪдÇëÇóÒ»°ã±È¶ÁÇëÇóÒªÖØÒª£¬ËùÒÔÈç¹ûÓжÁдÇëÇóͬʱ½øÐеĻ°£¬MYSQL½«»áÓÅÏÈÖ´ÐÐд²Ù×÷¡£ÕâÑùMyISAM±íÔÚ½øÐдóÁ¿µÄ¸üвÙ×÷ʱ£¨ÌرðÊǸüеÄ×Ö¶ÎÖдæÔÚË÷ÒýµÄÇé¿öÏ£©£¬»áÔì³É²éѯ²Ù×÷ºÜÄÑ»ñµÃ¶ÁËø£¬´Ó¶øµ¼Ö²éѯ×èÈû¡£
ÎÒÃÇ¿ÉÒÔͨ¹ýһЩÉèÖÃÀ´µ÷½ÚMyISAMµÄµ÷¶ÈÐÐΪ£º
a¡¢Í¨¹ýÖ¸¶¨Æô¶¯²ÎÊýlow-priority-updates£¬Ê¹MyISAMÒýÇæĬÈϸøÓè¶ÁÇëÇóÒÔÓÅÏȵÄȨÀû¡£
b¡¢Í¨¹ýÖ´ÐÐÃüÁîSET
LOW_PRIORITY_UPDATES=1£¬Ê¹¸ÃÁ¬½Ó·¢³öµÄ¸üÐÂÇëÇóÓÅÏȼ¶½µµÍ¡£
c¡¢Í¨¹ýÖ¸¶¨INSERT¡¢UPDATE¡¢DELETEÓï¾äµÄLOW_PRIORITYÊôÐÔ£¬½µµÍ¸ÃÓï¾äµÄÓÅÏȼ¶¡£
ÉÏÃæ3ÖÖ·½·¨¶¼ÊÇҪô¸üÐÂÓÅÏÈ£¬ÒªÃ´²éѯÓÅÏȵķ½·¨¡£ÕâÀïҪ˵Ã÷µÄ¾ÍÊÇ£¬²»ÒªÃ¤Ä¿µÄ¸ømysqlÉèÖÃΪ¶ÁÓÅÏÈ£¬ÒòΪһЩÐèÒª³¤Ê±¼äÔËÐеIJéѯ²Ù×÷£¬Ò²»áʹд½ø³Ì¡°¶öËÀ¡±¡£Ö»Óиù¾ÝÄãµÄʵ¼ÊÇé¿ö£¬À´¾ö¶¨ÉèÖÃÄÄÖÖ²Ù×÷ÓÅÏÈ¡£ÕâЩ·½·¨»¹ÊÇûÓдӸù±¾ÉÏͬʱ½â¾ö²éѯºÍ¸üеÄÎÊÌâ¡£
ÔÚÒ»¸öÓдóÊý¾ÝÁ¿¸ß²¢·¢±íµÄmysqlÀÎÒÃÇ»¹¿É²ÉÓÃÁíÒ»ÖÖ²ßÂÔÀ´½øÐÐÓÅ»¯£¬ÄǾÍÊÇͨ¹ýmysqlÖ÷´Ó£¨¶Áд£©·ÖÀëÀ´ÊµÏÖ¸ºÔؾùºâ£¬ÕâÑù¿É±ÜÃâÓÅÏÈÄÄÒ»ÖÖ²Ù×÷´Ó¶ø¿ÉÄܵ¼ÖÂÁíÒ»ÖÖ²Ù×÷µÄ¶ÂÈû¡£
ÍƼöÐÅÏ¢
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
ÆÀÂÛ