Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

¡¾×ª¡¿¼ÓËÙ¶¯Ì¬ÍøÕ¾Ö®MySQLË÷Òý·ÖÎöºÍÓÅ»¯

Ò»¡¢Ê²Ã´ÊÇË÷Òý£¿
Ë÷ÒýÓÃÀ´¿ìËÙµØÑ°ÕÒÄÇЩ¾ßÓÐÌض¨ÖµµÄ¼Ç¼£¬ËùÓÐMySQLË÷Òý¶¼ÒÔB-Ê÷µÄÐÎʽ±£´æ¡£Èç¹ûûÓÐË÷Òý£¬Ö´ÐвéѯʱMySQL±ØÐë´ÓµÚÒ»¸ö¼Ç¼¿ªÊ¼É¨ÃèÕû¸ö±íµÄËùÓмǼ£¬Ö±ÖÁÕÒµ½·ûºÏÒªÇóµÄ¼Ç¼¡£±íÀïÃæµÄ¼Ç¼ÊýÁ¿Ô½¶à£¬Õâ¸ö²Ù×÷µÄ´ú¼Û¾ÍÔ½¸ß¡£Èç¹û×÷ΪËÑË÷Ìõ¼þµÄÁÐÉÏÒѾ­´´½¨ÁËË÷Òý£¬MySQLÎÞÐèɨÃèÈκμǼ¼´¿ÉѸËٵõ½Ä¿±ê¼Ç¼ËùÔÚµÄλÖá£Èç¹û±íÓÐ1000¸ö¼Ç¼£¬Í¨¹ýË÷Òý²éÕҼǼÖÁÉÙÒª±È˳ÐòɨÃè¼Ç¼¿ì100±¶¡£
¼ÙÉèÎÒÃÇ´´½¨ÁËÒ»¸öÃûΪpeopleµÄ±í£º
¡¡
¡¡
¡¡¡¡CREATE TABLE people ( peopleid SMALLINT NOT NULL,
name CHAR(50) NOT NULL );
¡¡
¡¡
È»ºó£¬ÎÒÃÇÍêÈ«Ëæ»ú°Ñ1000¸ö²»Í¬nameÖµ²åÈëµ½people±í¡£ÔÚÊý¾ÝÎļþÖÐnameÁÐûÓÐÈκÎÃ÷È·µÄ´ÎÐò¡£Èç¹ûÎÒÃÇ´´½¨ÁËnameÁеÄË÷Òý£¬MySQL½«ÔÚË÷ÒýÖÐÅÅÐònameÁÐ,¶ÔÓÚË÷ÒýÖеÄÿһÏMySQLÔÚÄÚ²¿ÎªËü±£´æÒ»¸öÊý¾ÝÎļþÖÐʵ¼Ê¼Ç¼ËùÔÚλÖõēָÕ딡£Òò´Ë£¬Èç¹ûÎÒÃÇÒª²éÕÒnameµÈÓÚ“Mike”¼Ç¼µÄpeopleid£¨SQLÃüÁîΪ“SELECT peopleid from people WHERE name='Mike';”£©£¬MySQLÄܹ»ÔÚnameµÄË÷ÒýÖвéÕÒ“Mike”Öµ£¬È»ºóÖ±½Óתµ½Êý¾ÝÎļþÖÐÏàÓ¦µÄÐУ¬×¼È·µØ·µ»Ø¸ÃÐеÄpeopleid£¨999£©¡£ÔÚÕâ¸ö¹ý³ÌÖУ¬MySQLÖ»Ðè´¦ÀíÒ»¸öÐоͿÉÒÔ·µ»Ø½á¹û¡£Èç¹ûûÓГname”ÁеÄË÷Òý£¬MySQLҪɨÃèÊý¾ÝÎļþÖеÄËùÓмǼ£¬¼´1000¸ö¼Ç¼£¡ÏÔÈ»£¬ÐèÒªMySQL´¦ÀíµÄ¼Ç¼ÊýÁ¿Ô½ÉÙ£¬ÔòËüÍê³ÉÈÎÎñµÄËٶȾÍÔ½¿ì¡£
¶þ¡¢Ë÷ÒýµÄÀàÐÍ
MySQLÌṩ¶àÖÖË÷ÒýÀàÐ͹©Ñ¡Ôñ£º
ÆÕͨË÷Òý
ÕâÊÇ×î»ù±¾µÄË÷ÒýÀàÐÍ£¬¶øÇÒËüûÓÐΨһÐÔÖ®ÀàµÄÏÞÖÆ¡£ÆÕͨË÷Òý¿ÉÒÔͨ¹ýÒÔϼ¸ÖÖ·½Ê½´´½¨£º
´´½¨Ë÷Òý£¬ÀýÈçCREATE INDEX <Ë÷ÒýµÄÃû×Ö> ON tablename (ÁеÄÁбí);
ÐÞ¸Ä±í£¬ÀýÈçALTER TABLE tablename ADD INDEX [Ë÷ÒýµÄÃû×Ö] (ÁеÄÁбí);
´´½¨±íµÄʱºòÖ¸¶¨Ë÷Òý£¬ÀýÈçCREATE TABLE tablename ( [...], INDEX [Ë÷ÒýµÄÃû×Ö] (ÁеÄÁбí) );
ΨһÐÔË÷Òý
ÕâÖÖË÷ÒýºÍÇ°ÃæµÄ“ÆÕͨË÷Òý”»ù±¾Ïàͬ£¬µ«ÓÐÒ»¸öÇø±ð£ºË÷ÒýÁеÄËùÓÐÖµ¶¼Ö»ÄܳöÏÖÒ»´Î£¬¼´±ØÐëΨһ¡£Î¨Ò»ÐÔË÷Òý¿ÉÒÔÓÃÒÔϼ¸ÖÖ·½Ê½´´½¨£º
´´½¨Ë÷Òý£¬ÀýÈçCREATE UNIQUE INDEX <Ë÷ÒýµÄÃû×Ö> ON tablename (ÁеÄÁбí);
ÐÞ¸Ä±í£¬ÀýÈçALTER TABLE tablename ADD UNIQUE [Ë÷ÒýµÄÃû×Ö] (ÁеÄÁбí);
´´½¨±íµÄʱºòÖ¸¶¨Ë÷Òý£¬ÀýÈçCREATE TABLE tablename ( [...], UNIQUE [Ë÷ÒýµÄÃû×Ö] (ÁеÄÁбí) );
Ö÷¼ü


Ïà¹ØÎĵµ£º

MySQLÖÐInnoDBºÍMyISAMµÄ²î±ð

InnoDBºÍMyISAMÊÇÔÚʹÓÃMySQL×î³£ÓõÄÁ½¸ö±íÀàÐÍ£¬¸÷ÓÐÓÅȱµã£¬ÊÓ¾ßÌåÓ¦Óöø¶¨¡£ÏÂÃæÊÇÒÑÖªµÄÁ½ÕßÖ®¼äµÄ²î±ð£¬½ö¹©²Î¿¼¡£
innodb 
      InnoDB ¸ø MySQL ÌṩÁ˾ßÓÐÊÂÎñ(commit)¡¢»Ø¹ö(rollback)ºÍ±ÀÀ£ÐÞ¸´ÄÜÁ¦(crash recovery capabilities)µÄÊÂÎñ°²È«(transaction-safe (ACID complian ......

mysql ÃüÁî

1¡¢MySQL³£ÓÃÃüÁî
create database name; ´´½¨Êý¾Ý¿â
use databasename; Ñ¡ÔñÊý¾Ý¿â
drop database name Ö±½Óɾ³ýÊý¾Ý¿â£¬²»ÌáÐÑ
show tables; ÏÔʾ±í
describe tablename; ±íµÄÏêϸÃèÊö
select ÖмÓÉÏdistinctÈ¥³ýÖظ´×Ö¶Î
mysqladmin drop databasename ɾ³ýÊý¾Ý¿âÇ°£¬ÓÐÌáʾ¡£
ÏÔʾµ±Ç°mysql°æ±¾ºÍµ±Ç°È ......

mysql ÖРʱ¼äºÍÈÕÆÚº¯Êý

Ò»¡¢MySQL »ñµÃµ±Ç°ÈÕÆÚʱ¼ä º¯Êý
select now();
+---------------------+
| now()               |
+---------------------+
| 2008-08-08 22:20:46 |
+---------------------+
³ýÁË now() º¯ÊýÄÜ»ñµÃµ±Ç°µÄÈÕÆÚʱ¼äÍ⣬MySQL Öл¹ÓÐÏÂÃæµÄ ......

¡¾×ª¡¿MySQLÓÅ»¯ÊµÀý

ÔÚApache, PHP, MySQLµÄÌåϵ¼Ü¹¹ÖУ¬MySQL¶ÔÓÚÐÔÄܵÄÓ°Ïì×î´ó£¬Ò²ÊǹؼüµÄºËÐIJ¿·Ö¡£¶ÔÓÚDiscuz!ÂÛ̳³ÌÐòÒ²ÊÇÈç´Ë£¬MySQLµÄÉèÖÃÊÇ·ñºÏÀíÓÅ»¯£¬Ö±½ÓÓ°Ïìµ½ÂÛ̳µÄËٶȺͳÐÔØÁ¿£¡Í¬Ê±£¬MySQLÒ²ÊÇÓÅ»¯ÄѶÈ×î´óµÄÒ»¸ö²¿·Ö£¬²»µ«ÐèÒªÀí½âһЩMySQLרҵ֪ʶ£¬Í¬Ê±»¹ÐèÒª³¤Ê±¼äµÄ¹Û²ìͳ¼Æ²¢ÇÒ¸ù¾Ý¾­Ñé½øÐÐÅжϣ¬È»ºóÉèÖúÏÀíµÄ²ÎÊý¡ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ