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

´ÓMySQLÖлñµÃÊý¾Ý±íauto_incrementÖµµÄ·½·¨

ÎÊÌâÊÇÕâÑùµÄ£ºÔÚ²åÈëÒ»ÐÐÊý¾ÝÇ°¾ÍÏëÒªÖªµÀ½«Òª²úÉúµÄid¡£±ÈÈç˵ÏëÓÃÀ´ÃüÃûÉÏ´«µÄÎļþ¡£Èç¹û²»ÊÂÏÈ»ñµÃid¾Í²»ÖªµÀÎļþÃû£¬¾Íû·¨ÔÚ²åÈëʱ°ÑÎļþ·¾¶±£´æµ½Êý¾Ý¿âÀïÁË¡£Èç¹û²»ÐèÒªÊÂÏÈ»ñµÃid£¬´ó¿ÉÒÔÔÚ²åÈëºóµ÷ÓÃmysql_insert_id()»òÕßÖ´ÐÐselect last_insert_id()£¬¾Í²»±ØÍùÏ¿´ÁË¡£ÎªÁËÕÕ¹ËÐÔ¼±µÄͬѧ£¬Ïȸø´ð°¸£º
$result = mysql_query("show table status like 'tablename'");
$id = mysql_result($result, 0, 'Auto_increment');
ÆäÖÐtablenameÒª»»³ÉÊý¾Ý±íÃû£¬$id¾ÍÊÇauto_incrementÁеÄÏÂÒ»¸öÖµ¡£Ö»ÓÐÕâÖÖ°ì·¨ºÃÓã¬phpµÄ mysql_insert_id()£¬MySQLµÄselect last_insert_id()¡¢select @@last_insert_id¡¢select @@insert_id¡¢select @@identityÈ«¶¼²»ÐС£ÏëÖªµÀΪʲôµÄ»°¼ÌÐøÍùÏ¿´¡£
Ê×ÏÈÒª¸ãÇåÒ»µã£¬³ý·ÇÊÖ¶¯Ö¸¶¨£¬auto_incrementÊDz»ÓÃÖظ´ÖµµÄ¡£±ÈÈç˵Äãн¨Ò»ÕÅ±í£¬È»ºó²åÈë3ÐÐÊý¾Ý£¬idÖµÊÇ1¡¢2¡¢3£¬Ã»ÓÐÎÊÌâ¡£Èç¹ûÄã°Ñ2¡¢3ÄÇÁ½ÐÐɾµô£¬È»ºóÔÙ²åÈëÒ»ÐÐÊý¾Ý£¬ËüµÄidÖµÊǶàÉÙÄØ£¿ÊÇ2ô£¿ÊÇ4£¡Ò²ÐíÓеÄͬѧ»áÏ룺²»¶Ôѽ£¿MySQL²Î¿¼ÊÖ²áÉϲ»ÊÇдÁËô£º
µ±ÄúÏòÒ»¸öÒѱàÈëË÷ÒýµÄAUTO_INCREMENTÁÐÖвåÈëÒ»¸öNULLÖµ£¨½¨Ò飩»ò0ʱ£¬´ËÁб»ÉèÖÃΪÏÂÒ»¸öÐòÁеÄÖµ¡£Í¨³£Çé¿öÏÂΪvalue+1£¬´Ë´¦valueÊǵ±Ç°ÔÚ±íÖеÄÁеÄ×î´óÖµ¡£
û´í£¬µ«ÊÇMySQL²Î¿¼ÊÖ²áÉÏҲдÁË£º
Èç¹ûÄúɾ³ýµÄÐÐÖаüÀ¨ÓÃÓÚAUTO_INCREMENTÁеÄ×î´óÖµ£¬Ôò¸ÃÖµ±»ÖØÐÂÓÃÓÚBDB±í£¬µ«ÊDz»»á±»ÓÃÓÚMyISAM±í»òInnoDB±í¡£
BDBÊÇɶ£¿²éÁËһϣ¬ÊÇBerkeleyDB¡£ÎÒ¿´ÁËÒ»ÏÂÎÒµÄMySQL 5.0.51b£¬¸ù±¾ÕÒ²»µ½Õâ¸öÒýÇæ°¡¡£ÒÀÎÒ¿´£¬ÕâÁ½Ìõ¸ù±¾¾ÍÊÇ×ÔÏàì¶Ü£¬¶øÊÔÑéµÄ½á¹ûÊÇÇ°Õß´íºóÕ߶ԡ£ËùÒÔÏÂÃæÕâÖÖд·¨¾Í²»ÐÐÁË£º
select max(id)+1 from tablename
ÄÇôphpµÄmysql_insert_id()º¯ÊýÄØ£¿phpÊÖ²áÉÏд×Å£º
Èç¹ûÉÏÒ»²éѯûÓвúÉúAUTO_INCREMENTµÄÖµ£¬Ôòmysql_insert_id()·µ»Ø0¡£
ÄÇôÈç¹û¸Õ¸Õɾ³ýÁËÒ»ÐÐÊý¾ÝÏÖÔÚÓÖÏë²åÈëÔõô°ìÄØ£¿ÏÔÈ»ÏëÔÚ²åÈëÇ°È¡µ½ÖµÊDz»ÄÜÓÃËüµÄ¡£ÄÇôMySQLµÄlast_insert_id()º¯ÊýÄØ£¿MySQL²Î¿¼ÊÖ²áÀï˵£º
LAST_INSERT_ID() LAST_INSERT_ID(expr)
×Ô¶¯·µ»Ø×îºóÒ»¸öINSERT»òUPDATEÎÊѯΪAUTO_INCREMENTÁÐÉèÖõĵÚÒ»¸ö·¢ÉúµÄÖµ¡£
ÄÇôÈç¹ûÊÇÔÚµÚÒ»´Î²åÈëÊý¾Ý֮ǰÄØ£¿Èç¹ûÊý¾Ý·þÎñÆ÷ÖØÆôÁËÄØ£¿ÏÔȻҲ²»ÄÜÓ᣶øÇÒÆæ¹ÖµÄÊÇ£¬ÎÒÊÔÑéµÄ½á¹ûÊÇÕâ¸öº¯ÊýÒ»Ö±·µ»Ø0£¬²»ÖªÔõô¸ãµÄ¡£È«¾Ö±äÁ¿ÎÒÒ²ÊÔÁË£¬¸ö¸ö¶¼Îª0£¬ÕæÉñÁË¡£
×ÛÉÏ£¬Ö»ÓÐshow table status²»ÊÜÈÎ


Ïà¹ØÎĵµ£º

VB6.0ÈçºÎÓà libmySQL.dll API·ÃÎÊMYSQLÊý¾Ý¿â

MYSQL Ó¦ÓÃÊ®·Ö¹ã·¶£¬ºÜ¶àÍøÕ¾¼¸ºõ¶¼ÔÚÓÃËû£¬ÒòΪËûµÄСÇɺÍÁé»îÐԵȷ½ÃæÈÃÎÒ¾ö¶¨Òª¶ÔËû½øÐÐÑо¿£¬µ½ÏÖÔÚÒѾ­³É¹¦µÄ²»Óþ­¹ýODBC£¬ADOµÈ·½Ê½¾Í¿ÉÒÔ¶ÁÈ¡ºÍ¸üÐÂÊý¾Ý¡£
 
ºÃÁ˲»¶àÂÞ࣬ÒÔÏÂÎÒÀ´½éÉÜ×ܸö³ÌÐòµÄϸ½Ú:
 
£¨Ò»£©APIÉùÃ÷
 
1.  '·ÖÅä»ò³õʼ»¯ÊʺÏmysql_real_connect()µÄÒ»¸öMYSQL¶ÔÏñ¡ ......

¸ü¸ÄmysqlÊý¾Ý¿â±àÂëΪGBK

¸Õ¸Õ°²×°Íêmysqlºó
´ÓcmdÖнøÈëmysqlÊý¾Ý¿â
ÃüÁîÐÐÖÐÊäÈ룺
mysql -uroot -p123
½øÈëmysqlÊý¾Ý¿âÖÐ
ÃüÁîÐÐÖÐÊäÈë:
status;
²é¿´µ±Ç°Êý¾Ý¿âÖеıàÂë
ÈçÏ£º
--------------
mysql  Ver 14.12 Distrib 5.1.7-beta, for Win32 (ia32)
Connection id:       &nb ......

MySQL¸øÓû§ÃûÌíÃÜÂëµÄÎåÖÖ·½·¨£¨×ªÔØ£©

1.ͨ¹ýÐÞ¸ÄMYSQLÊý¾Ý¿âÖÐMYSQL¿âµÄUSER±í 
       ¾ÍÓÃÆÕͨµÄUPDATE¡¢INSERTÓï¾ä¾Í¿ÉÒÔ 
use mysql 
update user set Password=password('newpassword') where User='root'; 
flush privileges; 
£¨Õâ¸öÇ××ÔʵÑé¹ý£¬¿ÉÒÔÖ´ÐУ¡£©
2.ÔÚÃüÁîÐÐÖÐʹÓÃÈçÏÂÃüÁî 
&nbs ......

MYSQL »ñÈ¡µ±Ç°ÈÕÆÚ¼°ÈÕÆÚ¸ñʽ

MYSQL »ñÈ¡µ±Ç°ÈÕÆÚ¼°ÈÕÆÚ¸ñʽ
   »ñȡϵͳÈÕÆÚ£º  NOW()
   ¸ñʽ»¯ÈÕÆÚ£º    DATE_FORMAT(date, format)
               ×¢£º   date£ºÊ±¼ä×Ö¶Î
       ......

tomcatÁ´½Ó³ØÁ´½ÓMysqlÊý¾Ý¿âÖÐÎÄÂÒÂë½â¾ö°ì·¨

1¡¢Ê×ÏÈ×Ô¼ºÐ½¨µÄÊý¾Ý¿â±àÂë¸ñʽÉèΪUTF-8
2¡¢½«mysql-connector-java-5.1.6-bin¿½±´µ½tomcat\LibĿ¼Ï¡£
3¡¢ÐÞ¸ÄTomcat\conf\ϵÄcontext.xmlÎļþÄÚÈÝÈçÏ£º
<Context>
 <WatchedResource>WEB-INF/web.xml</WatchedResource>
 <Resource
  name="jdbc/mysqlds"
  t ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ