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

mysql ×ÔÔöÁÐÏà¹ØÎÊÌâÕûÀí

MYSQL×ÔÔöÁÐ
1.¹Ø¼ü×Ö £ºauto_increment
2.×ÔÔöÓ÷¨
Àý:
CREATE TABLE animals ( id mediumint not null auto_increment,
name char(30) not null,
primary key (id));
3.¹ØÓÚ×ÔÔö
Q:Ôõô»ñµÃµ±Ç°µÄ×ÔÔöµÄ×î´óÖµ?
A:select @@identity
Q:Ôõô»ñµÃtableµÄµ±Ç°×ÔÔö×î´óÖµ?
A:select max(id) from table
Q:¶Ô×ÔÔöµÄÀí½â?
A: Ò»°ãÇé¿öÏ»ñÈ¡¸Õ²åÈëµÄÊý¾ÝµÄid£¬Ê¹ÓÃselect max(id) from table ÊÇ¿ÉÒԵġ£LAST_INSERT_ID ÊÇÓëtableÎ޹صģ¬Èç¹ûÏò±ía²åÈëÊý¾Ýºó£¬ÔÙÏò±íb²åÈëÊý¾Ý£¬LAST_INSERT_ID»á¸Ä±ä¡£
ʹÓõ¥INSERTÓï¾ä²åÈë¶àÌõ¼Ç¼, LAST_INSERT_ID·µ»ØÒ»¸öÁÐ±í¡£
@@identityÊDZíʾµÄÊÇ×î½üÒ»´ÎÏò¾ßÓÐidentityÊôÐÔ(¼´×ÔÔöÁÐ)µÄ±í²åÈëÊý¾Ýʱ¶ÔÓ¦µÄ×ÔÔöÁеÄÖµ£¬ÊÇϵͳ¶¨ÒåµÄÈ«¾Ö±äÁ¿¡£±ÈÈçÓиö±íA£¬ËüµÄ×ÔÔöÁÐÊÇid£¬µ±ÏòA±í²åÈëÒ»ÐÐÊý¾Ýºó£¬Èç¹û²åÈëÊý¾Ýºó×ÔÔöÁеÄÖµ×Ô¶¯Ôö¼ÓÖÁ101£¬Ôòͨ¹ýselect@@identityµÃµ½µÄÖµ¾ÍÊÇ101¡£
×¢:LAST_INSERT_IDÊÇÒ»¸öº¯Êý.
Ó÷¨:LAST_INSERT_ID()
Q:MYSQLÖеÄLAST_INSERT_ID()ºÍMSSQLÖеÄ@@IDENTITY
A:°´ÕÕÓ¦ÓÃÐèÒª£¬³£³£ÒªÈ¡µÃ¸Õ¸Õ²åÈëÊý¾Ý¿â±íÀïµÄ¼Ç¼µÄIDÖµ¡£
ÔÚMYSQLÖпÉÒÔʹÓÃLAST_INSERT_ID()º¯Êý£¬ÔÚMSSQLÖÐʹÓÃ@@IDENTITY¡£Í¦·½±ãµÄÒ»¸öº¯Êý¡£
µ«ÊÇ£¬ÕâÀïÐèҪעÒâµÄÊÇ£¬µ±Ê¹ÓÃINSERTÓï¾ä²åÈë¶àÌõ¼Ç¼µÄʱºò£¬Ê¹ÓÃLAST_INSERT_ID()·µ»ØµÄ»¹ÊǵÚÒ»ÌõµÄIDÖµ£¬¶ø@@IDENTITY·µ»Ø×îºóÒ»Ìõ¡£
Q:mysql_insert_id()ÓëLAST_INSERT_ID()
A:mysql_insert_id() ½« MySQL ÄÚ²¿µÄ C API º¯Êý mysql_insert_id() µÄ·µ»Øֵת»»³É long£¨PHPÖÐÃüÃûΪint£©¡£Èç¹û AUTO_INCREMENT µÄÁеÄÀàÐÍÊÇ BIGINT£¬Ôò mysql_insert_id() ·µ»ØµÄÖµ½«²»ÕýÈ·¡£¿ÉÒÔÔÚ SQL²éѯÖÐÓà MySQL ÄÚ²¿µÄ SQL º¯Êý LAST_INSERT_ID() À´Ìæ´ú¡£
MySQLµÄLAST_INSERT_ID()µÄ½éÉÜ mysql_insert_id()¾ÍÊǵ÷ÓÃLAST_INSERT_ID()À´ÊµÏֵġ£
ÔÚmysqlÖÐÓÃlast_insert_id()....ÔÚ³ÌÐòÖÐÓÃmysql_insert_id().
4.ÈçºÎÖØÖÃÖÖ×Óµ½1£º
truncate ÖØÖÃÖÖ×ÓÖµµ½“1” ¡£
5.select * from table_name where auto_increment_col_name is NULL »ñµÃ×îºó²åÈëµÄµÚÒ»ÐÐÊý¾Ý£»¼´Ê¹Ò»´ÎÐÔ²å´óÅúÊý¾ÝÒ²ÊÇÖ»·µ»Ø¸ÃÅú´ÎµÚÒ»ÐÐ×ÔÔöºóµÄÖµ£¡
ÌØÊâµÄ£º¶ÔÓÚmyisam±í£¬ÌØÊâµÄ¶ÔÓÚmyisamÒýÇæµÄ±í£¬Äã¿ÉÒÔÔÚÒ»¸ö¶àÁÐË÷ÒýÉϵĵڶþÁÐÉ϶¨Òå×ÔÔöÁУº½«ÔÚµÚÒ»Ë÷ÒýÁÐÉϲúÉú×ÔÔö£¬¿ÉÒÔÀí½âΪ£ºÔÚµÚÒ»Ë÷ÒýÁÐÉÏ·Ö×飬¼ÆËã¸Ã×éÉϵÄ×î´óÖµ£¬+1¡£¸ÃÐ


Ïà¹ØÎĵµ£º

MySQL Ìí¼ÓÍâ¼ü

MySQL Ìí¼ÓÍâ¼ü
DROP TABLE IF EXISTS `nation`;
CREATE TABLE `nation`(
    `pii_Nation` smallint(2) unsigned NOT NULL default '0',
    `pii_NatinoName` varchar(40) NOT NULL default '',
    PRIMARY KEY  (`pii_Nation`)
)ENGINE=InnoDB DEFAULT CHARSE ......

ÈÃmysql Äܹ»Ô¶³ÌÁ¬½Ó

mysql error number 2003   
Can't connect to MySQL server xxx.xxx.xxx.xxx (10061)
ÔÚubuntu 9.04ÖÐĬÈÏ°²×°ÁËmysql£¬Ä¬ÈÏÖ»Äܱ¾µØ·ÃÎÊ£¬googleÁËһϣº
²ÉÓÃ
µÇ¼µ½MySQL·þÎñÆ÷¶Ë£¬ÔÚmysql¿âÏÂÖ´ÐÐ
grant all on *.* to 'remote'@'172.16.21.39' identified by 'password';
¼´¿É
Èç¹ûÒªÉèÖÃΪ ......

mysqlÖÐʱ¼ä²éѯº¯Êý£¨°üÀ¨Ê±¼ä´Á£©

ÕâЩº¯Êý¶¼ÊÇMySQL×Ô´øµÄ£¬¿ÉÒÔÖ±½ÓʹÓÃÔÚPHPдµÄMySQL²éѯÓï¾äÖÐŶ
1-CURDATE()»òCURRENT_DATE()ºÍCURTIME()»òCURRENT_TIME()
ÕâÁ½¸öº¯ÊýÊDZȽϳ£Óõ½µÄ£¬¹ËÃû˼Ò壬µÚÒ»¸ö·µ»Øµ±Ç°ÈÕÆÚ£¬µÚ¶þ¸ö·µ»Øµ±Ç°Ê±¼ä
¿ÉÒÔÔÚMySQL¿Í»§¶Ë»òÕßPHPÓï¾äÀïд"SELECT CURDATE(),CURTIME()"²é¿´Ïà¹ØÐÅÏ¢.
»¹ÓÐÒ»¸öºÜÖØÒªµÄº¯ ......

MySQL my.ini ÅäÖÃÎļþÏê½â


¡¡¡¡(1)¡¢back_log£º
¡¡¡¡ÒªÇó MySQL ÄÜÓеÄÁ¬½ÓÊýÁ¿¡£µ±Ö÷ÒªMySQLÏß³ÌÔÚÒ»¸öºÜ¶Ìʱ¼äÄڵõ½·Ç³£¶àµÄÁ¬½ÓÇëÇó£¬Õâ¾ÍÆð×÷Óã¬È»ºóÖ÷Ï̻߳¨Ð©Ê±¼ä(¾¡¹ÜºÜ¶Ì)¼ì²éÁ¬½Ó²¢ÇÒÆô¶¯Ò»¸öÐÂÏ̡߳£
¡¡¡¡back_logÖµÖ¸³öÔÚMySQLÔÝʱֹͣ»Ø´ðÐÂÇëÇó֮ǰµÄ¶Ìʱ¼äÄÚ¶àÉÙ¸öÇëÇó¿ÉÒÔ±»´æÔÚ¶ÑÕ»ÖС£Ö»ÓÐÈç¹ûÆÚÍûÔÚÒ»¸ö¶Ìʱ¼äÄÚÓкܶàÁ¬½Ó£¬ ......

MySQLÓÅ»¯

MySQLÓÅ»¯
ͬʱÔÚÏß·ÃÎÊÁ¿¼ÌÐøÔö´ó£¬¶ÔÓÚ1GÄÚ´æµÄ·þÎñÆ÷Ã÷ÏԸоõµ½³ÔÁ¦ÑÏÖØʱÉõÖÁÿÌ춼»áËÀ»ú£¬»òÕßʱ²»Ê±µÄ·þÎñÆ÷¿¨Ò»Ï£¬Õâ¸öÎÊÌâÔø¾­À§ÈÅÁËÎÒ°ë¸ö¶àÔ¡£MySQLʹÓÃÊǺܾßÉìËõÐÔµÄËã·¨£¬Òò´ËÄãͨ³£ÄÜÓúÜÉÙµÄÄÚ´æÔËÐлò¸øMySQL¸ü¶àµÄ±»´æÒԵõ½¸üºÃµÄÐÔÄÜ¡£
°²×°ºÃmysqlºó£¬ÅäÖÆÎļþÓ¦¸ÃÔÚ/usr/local/mysql/share/mysql ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ