Mysql·þÎñÆ÷ÈçºÎµÃµ½×î¼ÑÐÔÄÜÓÅ»¯
My favorite question during Interview for people to work as MySQL DBAs or be involved with MySQL Performance in some way is to ask them what should be tuned in MySQL Server straight after installation, assuming it was installed with default settings.
ÔÚÃæÊÔMySQL DBA»òÕßÄÇЩ´òËã×öMySQLÐÔÄÜÓÅ»¯µÄÈËʱ£¬ÎÒ×îϲ»¶ÎÊÌâÊÇ£ºMySQL·þÎñÆ÷°´ÕÕĬÈÏÉèÖð²×°ÍêÖ®ºó£¬Ó¦¸Ã×öÄÄЩ·½ÃæµÄµ÷½ÚÄØ£¿
I’m surprised how many people fail to provide any reasonable answer to this question, and how many servers are where in wild which are running with default settings.
ÁîÎҺܾªÑȵÄÊÇ£¬ÓжàÉÙÈ˶ÔÕâ¸öÎÊÌâÎÞ·¨¸ø³öºÏÀíµÄ´ð°¸£¬ÓÖÓжàÉÙ·þÎñÆ÷¶¼ÔËÐÐÔÚĬÈϵÄÉèÖÃÏ¡£
Even though you can tune quite a lot of variables in MySQL Servers only few of them are really important for most common workload. After you get these settings right other changes will most commonly offer only incremental performance improvements.
¾¡¹ÜÄã¿ÉÒÔµ÷½ÚºÜ¶àMySQL·þÎñÆ÷ÉϵıäÁ¿£¬µ«ÊÇÔÚ´ó¶àÊýͨ³£µÄ¹¤×÷¸ºÔØÏ£¬Ö»ÓÐÉÙÊý¼¸¸ö²ÅÕæÕýÖØÒª¡£Èç¹ûÄã°ÑÕâЩ±äÁ¿ÉèÖÃÕýÈ·ÁË£¬ÄÇôÐÞ¸ÄÆäËû±äÁ¿×î¶àÖ»ÄܶÔϵͳÐÔÄܸÄÉÆÓÐÒ»¶¨ÌáÉý¡£
key_buffer_size - Very important if you use MyISAM tables. Set up to 30-40% of available memory if you use MyISAM tables exclusively. Right size depends on amount of indexes, data size and workload - remember MyISAM uses OS cache to cache the data so you need to leave memory for it as well, and data can be much larger than indexes in many cases. Check however if all of key_buffer is used over time - it is not rare to see key_buffer being set to 4G while combined size of .MYI files is just 1GB. This would be just a waste. If you use few MyISAM tables you’ll want to keep it lower but still at least 16-32Mb so it is large enough to accommodate indexes for temporary tables which are created on disk.
key_buffer_size - Õâ¶ÔMyISAM±íÀ´Ëµ·Ç³£ÖØÒª¡£Èç¹ûÖ»ÊÇʹÓÃMyISAM±í£¬¿ÉÒÔ°ÑËüÉèÖÃΪ¿ÉÓÃÄÚ´æµÄ 30-40%¡£ºÏÀíµÄֵȡ¾öÓÚË÷Òý´óС¡¢Êý¾ÝÁ¿ÒÔ¼°¸ºÔØ — ¼Çס£¬MyISAM±í»áʹÓòÙ×÷ϵͳµÄ»º´æÀ´»º´æÊý¾Ý£¬Òò´ËÐèÒªÁô³ö²¿·ÖÄÚ´æ¸øËüÃÇ£¬ºÜ
Ïà¹ØÎĵµ£º
Class.forName("com.mySQL.jdbc.Driver");
String strUrl="jdbc:mysql://localhost:3306/stu?useUnicode=true&characterEncoding=GB2312";
String strUser="nuey";
String strPassword="password";
Connection conn=DriverManager.getCon ......
MySQL·þÎñÆ÷°üº¬Ò»Ð©ÆäËûSQL DBMSÖв»¾ß±¸µÄÀ©Õ¹¡£×¢Ò⣬Èç¹ûʹÓÃÁËËüÃÇ£¬½«ÎÞ·¨°Ñ´úÂëÒÆÖ²µ½ÆäËûSQL·þÎñÆ÷¡£ÔÚijЩÇé¿öÏ£¬Äã¿ÉÒÔ±àд°üº¬MySQLÀ©Õ¹µÄ´úÂ룬µ«ÈÔ±£³ÖÆä¿ÉÒÆÖ²ÐÔ£¬·½·¨ÊÇÓÓ/*... */”×¢Ê͵ôÕâЩÀ©Õ¹¡£MySQL·þÎñÆ÷Äܹ»½âÎö²¢Ö´ÐÐ×¢ÊÍÖеĴúÂ룬¾ÍÏñ¶Ô´ýÆäËûMySQLÓï¾äÒ»Ñù£¬µ«ÆäËûSQL·þÎñÆ÷½«ºöÂÔ ......
Êý¾Ý¿â²Ù×÷ÀࣺDBCommon.class.php
//---------------------------------------------------------------------
// MySQL Master/SlaveÊý¾Ý¿â¶Áд²Ù×÷Àà
//
// ¿ª·¢×÷Õß: heiyeluren
// °æ±¾ÀúÊ·:
// 2006-09-20 »ù±¾µ¥Êý¾Ý¿â²Ù×÷¹¦ÄÜ, 25 ¸ö½Ó¿Ú
// 2007-07-30 Ö§³Öµ ......
LAST_INSERT_ID
×Ô¶¯·µ»Ø×îºóÒ»¸ö INSERT »ò UPDATE ²Ù×÷Ϊ AUTO_INCREMENT ÁÐÉèÖõĵÚÒ»¸ö·¢ÉúµÄÖµ. ²Î¿¼ÕâÀï
The ID that was generated is maintained in the server on a per-connection basis.
LAST_INSERT_IDÊÇ»ùÓÚµ¥¸öconnectionµÄ, ²»¿ÉÄܱ»ÆäËüµÄ¿Í»§¶ËÁ¬½Ó¸Ä±ä¡£
¿ÉÒÔÓà SELECT LAST_INSERT_ID(); ²éѯLAST ......