mysql Ë÷Òý»úÖÆ
Chapter 4. Indexes
Ë÷ÒýÓÐÖúÓÚMySQLÔÚºÆÈçÑ̺£µÄÊý¾ÝÖÐѸËÙÕÒµ½ºÍÈ¡µÃÕýÈ·µÄ¼Ç¼¡£
4.1 Indexing Basics
4.1.1 Index Concepts
Ë÷ÒýÊÇ°´ÕÕijÖÖ¹æÔòÅÅÐòµÄ¡£Ë÷ÒýÒ²¾ÍÊÇÎþÉüһЩ¿Õ¼äºÍcpuµÄ¿ªÏúÀ´Ê¹ÄãµÄ²éѯÅܵøü¿ìµã¡£ÁíÍâÌáÐѵÄÊÇ£¬¶ÔÓÚMySQLÀ´½²£¬ÊõÓï“Key”ºÍ“Index”ÊÇ¿ÉÒÔ»¥ÏàÌæ»»µÄ¡£
4.1.1.1 Partial indexes
Ë÷ÒýÊÇÒԿռ任ȡÐÔÄÜ¡£µ«ÓÐʱºò²»ÏëºÄ·ÑÌ«¶àµÄ¿Õ¼äµÄ»°£¬MySQLÓÐһϵÁпØÖÆË÷Òý¿Õ¼äµÄ·½·¨¡£ÀýÈçÄã¿ÉÒÔ¿ØÖÆË÷Òý×Ö½Ú£¬²ÉÈ¡²¿·ÖË÷ÒýµÄ·½·¨£¬µ±È»ÕâÑùÐÔÄܻήµÍһЩ¡£
ALTER TABLE
phonebook ADD INDEX
(last
name(4))
4.1.1.2 Multicolumn indexes
ʹÓöàÁÐË÷ÒýµÄÔÒòÔÚÓÚ£ºMySQL will only ever use one index per table per query¡£
4.1.1.3 Index order
MySQLÎÞÐèÈ˹¤¸ÉÔ¤Ë÷ÒýµÄÅÅÐò£¬Ëü»á´¦ÀíµÃºÜºÃ¡£
4.1.1.4 Indexes as constraints
ΨһË÷Òý£¨unique index£©±êÃ÷ÔÚ¸ø¶¨µÄÁÐÀïÌØÖµÖ»ÄܳöÏÖÒ»´Î¡£Î¨Ò»Ë÷ÒýÓÐÁ½¸ö×÷ÓãºÒ»¸ö¾ÍÊÇ°ïÖú²éѯѸËÙ¶¨Î»£»¶þ¾ÍÊǵ±²åÈë»ò¸üÐÂʱ£¬±£Ö¤ÁÐÀïµÄÖµµÄΨһÐÔ¡£Õâ¾ÍÒâζ×Å£¬ÔÚÕâÀΨһË÷ÒýÆðµ½ÁËÔ¼ÊøµÄ×÷Óá£
ALTER TABLE
phonebook ADD UNIQUE
(phone
number)
4.1.1.5 Clustered and secondary indexes
¾Û¼¯Ë÷Òý£¨clustered
index£©½«Ö÷¼üºÍ¼Ç¼ֱ½Ó¹Ò¹³£¬¶øÇҼǼÊǸù¾ÝÖ÷¼üÀ´ÅÅÐòµÄ¡£Ã¿Ò»¸ö±íÖ»ÄÜÓÐÒ»¸ö¾Û¼¯Ë÷Òý£¬ÕâºÜºÃÀí½â£¬ÒòΪ¼Ç¼ֻÄÜÓÃÒ»ÖÖ·½·¨À´ÅÅÐò¡£µ±Äãͨ¹ýÖ÷¼ü
À´²éѯÊý¾ÝµÄʱºò£¬¾Û¼¯Ë÷Òý·Ç³£¿ì¡£ÒòΪËüÖ»ÒªÒ»´Î²éѯ¾Í¿ÉÒԵõ½½á¹û£¬¶ø±ê×¼µÄMyISAMµÄË÷ÒýÐèÒªÁ½´Î²éѯ£¬ÏȲ鵽Ë÷Òý£¬È»ºóͨ¹ýË÷ÒýµÃµ½µÄλÖÃÔÙ
È¥²éÊý¾Ý¡£
4.1.1.6 Unique indexes versus primary keys
Ö÷¼üÆäʵ¾ÍÊÇÒ»ÖÖ²»ÄÜ°üÀ¨ÊýÖµNULLµÄΨһË÷Òý¡£Ö÷¼ü¶ÔÓÚMyISAMÒýÇæ²»ÊDZØÐèµÄ£¬µ«¶ÔÓÚInnoDB ºÍBDBÒýÇæÀ´½²ÊDZØÐèµÄ£¬Èç¹ûÄã²»ÉùÃ÷£¬ËûÃÇ»áÒþº¬Ìí¼ÓÒ»¸öÖ÷¼ü
4.1.1.7 Indexing NUL
Ls
4.2 Index Structures
ÕâÒ»½Ú×÷Õß²»»áÉϸ½Ú£¬ËûÖ»Ïë½â¾öÕ⼸¸öÎÊÌ⣺ÄÇÖÖË÷ÒýÀàÐÍËÙ¶È×î¿ì£¿ÄÇÖÖÁé»îÐÔ×îºÃ£¿ÄÇÖÖÕ¼ÓõĿռä×îÉÙ£¿
4.2.1 B-Tree Indexes
B-Tree£¨balance tree£©ÊÇÄ¿Ç°×îÁ÷ÐеÄË÷ÒýÀàÐÍ£¬ÒòΪËüÔÚÁé»îÐÔ£¬¿Õ¼äÕ¼ÓúÍ×ÛºÏÐÔÄܶ¼±È½ÏÓÅÒì¡£
B-Tree¹ËÃû˼Òå¾ÍÊÇÊ÷Ðνṹ£¬Ã¿¸ö½Úµã°´ÕÕË÷ÒýµÄÊýÖµÀ´°²ÅÅ¡£ÒòΪÊÇbalanceÂð£¬ËùÒÔÔÚÌí¼ÓºÍÈ¥³ý½Úµãºó£¬B-TreeÒ²²»»áʧȥƽºâ£¬Ëü»á×Ô¶¯µ÷½Ú¡£ÕâÖֽṹµÄºÃ´¦¾ÍÔÚÓÚ¼´Ê¹ÔÚ×µÄÇé¿öÏÂÈÔÈ»¿ÉÒԵõ½±È½Ï
Ïà¹ØÎĵµ£º
³£ÓÃMySQLµÄͯЬ¶¼ÖªµÀÕâ¸ömyisamÀàÐÍµÄ±í¼«ÈÝÒ×Ë𻵣¬¶àÊýÈË¿ÉÄܶ¼ÊÇÓÃmyisamchkÃüÁîÀ´È˹¤ÐÞ¸´£¬ÏÂÃæ½éÉÜÒ»ÖÖ×Ô¶¯ÐÞ¸´myisamµÄ·½·¨£¬Ò²ÊÇÎÒÉÏÎç¸ÕѧµÄ£¬¹²Í¬½ø²½£¬ºÇºÇ~
ÔÚMySQLµÄÅäÖÃÎļþmy.cnfÖУ¬Æô¶¯Ï·Ö¼ÓÈëmyisam-recoverÉèÖÃÊý¾Ý»Ö¸´¹¦ÄÜ£¬¾ßÌå ......
MySQLÊý¾Ý¿â½Ó¿ÚµÄVCʵÏÖÓëÓ¦ÓÃ...phpma¿ªÔ´
ÕªÒª£ºMySQLÊý¾Ý¿â×÷ΪһÖÖÍøÂçÊý¾Ý¿âÐÔÄÜÊ®·Ö³öÉ«£¬µ«ÆäÔÚÓ¦ÓÃÈí¼þÖÐʹÓýÏÉÙ¡£±¾ÎĽ«Ö÷Ҫ̽ÌÖMySQLÌṩµÄÁ½ÖÖÊý¾Ý¿â½Ó¿Ú ——£¨ODBC APIºÍC API£©ÔÚVCÖеÄÓ¦Ó㬲¢ÇÒÐγÉÒ»¸öÀàÓÃÒÔ·â×°C APIÊý¾Ý¿â½Ó¿ÚµÄ¹¦ÄÜ¡£phpma¿ª ......
¹Ø¼ü×Ö: key×Ö¶ÎÊÇmysqlÀïÃæµÄ¹Ø¼ü×Ö
insert into app(name,created,key,secret,masterSecret) values ('aa',null,null,null,null);
ÒòΪÕâÀïµÄkey×Ö¶ÎÊÇmysqlµÄ¹Ø¼ü×Ö£¬ËùÒÔÒ»Ö±²å²»½øÈ¥¡£
ÐÞ¸ÄÈçÏÂ:ÔÚkeyµÄÍ·ÉϼÓÉÏÁ½µã(·´ÒýºÅ£¬ËüÔÚ¼üÅ̵Ä~Õâ¸ö¼üÉÏ)¡£¼´¿É¸ã¶¨
sql½¨±íÈçÏ£º
Java´úÂë
CREATE T ......
Óï·¨:
/usr/local/mysql/bin/mysqladmin -u username -p newpassword
ϵͳ»áÌáʾÄúÊäÈë¾ÉÃÜÂë:
°´Enterºó,ϵͳ½«¾ÉµÄÃÜÂë¸Ä³Énewpassword,
×¢Òânewpassword²»ÊÇÃüÁî,ÊÇÒ»¸ö×Ö´®,¾ÍÊÇÐÂÃÜÂëµÄ×Ö´®,Äã¿ÉÒÔ¸ü¸Ä³ÉÆäËüµÄ.
-uºóÃæ¸ú×ÅÊÇÓû§Ãû,¾ÍÊÇÄãËùÒª¸ü¸ÄµÄÓû§Ãû. ......
µÚÒ»ÕС¢mysql·þÎñµÄÆô¶¯ºÍÍ£Ö¹
net stop mysql
net start mysql
µÚ¶þÕС¢µÇ½mysql
Óï·¨ÈçÏ£º mysql -uÓû§Ãû -pÓû§ÃÜÂë
¼üÈëÃüÁîmysql -uroot -p£¬ »Ø³µºóÌáʾÄãÊäÈëÃÜÂ룬ÊäÈë12345£¬È»ºó»Ø³µ¼´¿É½øÈëµ½mysqlÖÐÁË£¬mysqlµÄÌáʾ·ûÊÇ£º
mysql>
×¢Ò⣬Èç¹ûÊÇÁ¬½Óµ½ÁíÍâµÄ»úÆ÷ÉÏ£¬ÔòÐèÒª¼ÓÈëÒ»¸ö²ÎÊý-h»úÆ÷IP
µ ......