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

mysql¼¶ÁªÉ¾³ý Mysql µÄ Cascade Restrict

½ñÌìÓöµ½Êý¾Ý¿âµÄÒ»¸öÎÊÌ⣬¾ÍÊÇÿµ±´ÓÖ÷±íÖÐɾ³ýÒ»¸öÖ÷¼üidʱ£¬ÓÉÓÚÓëËûÏà¹ØÁªµÄ±íÖÐÓÐÏà¹ØµÄ×Ö¶ÎÊý¾Ý£¬ËùÒÔÎÞ·¨É¾³ý¡£²éÁËÒ»´ó¶Ñ×ÊÁÏ£¬·¢ÏÖÎÒ½¨±í¹ØÁªÓõÄÊÇon Restrict.¿ÉÄÜÎÊÌâ¾Í³öÔÚÕâÀï°É¡£ 
Íâ¼üÔ¼Êø¶Ô×Ó±íµÄº¬Òå: 
  Èç¹ûÔÚ¸¸±íÖÐÕÒ²»µ½ºòÑ¡¼ü,Ôò²»ÔÊÐíÔÚ×Ó±íÉϽøÐÐinsert/update 
Íâ¼üÔ¼Êø¶Ô¸¸±íµÄº¬Òå: 
  ÔÚ¸¸±íÉϽøÐÐupdate/deleteÒÔ¸üлòɾ³ýÔÚ×Ó±íÖÐÓÐÒ»Ìõ»ò¶àÌõ¶ÔӦƥÅäÐеĺòÑ¡¼üʱ,¸¸±íµÄÐÐΪȡ¾öÓÚ£ºÔÚ¶¨Òå×Ó±íµÄÍâ¼üʱָ¶¨µÄon update/on delete×Ó¾ä, InnoDBÖ§³Ö£µÖÖ·½Ê½, ·ÖÁÐÈçÏ 
  
  . cascade·½Ê½ 
   ÔÚ¸¸±íÉÏupdate/delete¼Ç¼ʱ£¬Í¬²½update/deleteµô×Ó±íµÄÆ¥Åä¼Ç¼ 
   On delete cascade´Ómysql3.23.50¿ªÊ¼¿ÉÓÃ; on update cascade´Ómysql4.0.8¿ªÊ¼¿ÉÓà
  . set null·½Ê½ 
   ÔÚ¸¸±íÉÏupdate/delete¼Ç¼ʱ£¬½«×Ó±íÉÏÆ¥Åä¼Ç¼µÄÁÐÉèΪnull 
   ҪעÒâ×Ó±íµÄÍâ¼üÁв»ÄÜΪnot null 
   On delete set null´Ómysql3.23.50¿ªÊ¼¿ÉÓÃ; on update set null´Ómysql4.0.8¿ªÊ¼¿ÉÓà
  . No action·½Ê½ 
   Èç¹û×Ó±íÖÐÓÐÆ¥ÅäµÄ¼Ç¼,Ôò²»ÔÊÐí¶Ô¸¸±í¶ÔÓ¦ºòÑ¡¼ü½øÐÐupdate/delete²Ù×÷ 
   Õâ¸öÊÇANSI SQL-92±ê×¼,´Ómysql4.0.8¿ªÊ¼Ö§³Ö 
  . Restrict·½Ê½ 
   ͬno action, ¶¼ÊÇÁ¢¼´¼ì²éÍâ¼üÔ¼Êø 
  . Set default·½Ê½ 
   ½âÎöÆ÷ÈÏʶÕâ¸öaction,µ«Innodb²»ÄÜʶ±ð£¬²»ÖªµÀÊÇʲôÒâ˼£®£®£® 
  
  ×¢Ò⣺trigger²»»áÊÜÍâ¼ücascadeÐÐΪµÄÓ°Ïì,¼´²»»á½â·¢trigger 
ÔÚmysqlÖУ¬Óë£Ó£Ñ£Ì±ê×¼ÏàÎ¥±³µÄÈýµã 
1.       Èç¹ûÔÚ¸¸±íÖÐÓжà¸ökeyÖµÏàͬ£¬ÄÇôÔÚ½øÐÐÍâ¼ücheckʱ,»áµ±³ÉÓÐÏàͬkeyÖµµÄÆäËûÐв»´æÔÚ; ±ÈÈçµ±¶¨ÒåÁËÒ»¸örestrictÐÐΪÍâ¼üʱ,Ò»¸ö×Ó±íÐжÔÓ¦µ½¶à¸ö¸¸±íÐÐ(¾ßÓÐÏàͬkeyÖµ), Innodb²»ÔÊÐíɾ³ý¸¸±íÉϵÄËùÓÐÕâЩÐР
2.       ¸¸×Ó±íÊÇͬһ¸ö±í,×ÔÎÒ²ÎÕÕʱ²»ÔÊÐíÖ¸¶¨on update cascade, on update set null 
´Ómysql4.0.13¿ªÊ¼£¬ÔÊÐíͬһ¸ö±íÉϵÄon delete set null 
´Ómysql4.0.21¿ªÊ¼£¬ÔÊÐíͬһ¸ö±íÉϵÄon delete cascade 
µ«¼¶Áª²ã´Î²»


Ïà¹ØÎĵµ£º

mysql ³£¼û´íÎ󼯺Ï


 
1£º Can’t connect to [local] MySQL server´íÎó
Ò»¸öMySQL¿Í»§¿ÉÒÔÁ½ÖÖ²»Í¬µÄ·½Ê½Á¬½Ómysqld·þÎñÆ÷£ºUnixÌ×½Ó×Ö£¬Ëüͨ¹ýÔÚÎļþϵͳÖеÄÒ»¸öÎļþ(ȱʡ“/tmp /mysqld.sock”)½øÐÐÁ¬½Ó£»»òTCP/IP£¬Ëüͨ¹ýÒ»¸ö¶Ë¿ÚºÅÁ¬½Ó¡£UnixÌ×½Ó×Ö±ÈTCP/IP¸ü¿ì£¬µ«ÊÇÖ»ÓÐÓÃÔÚÁ¬½Óͬһ̨¼ÆËã»úÉϵķþÎñÆ÷¡£Èç¹ûÄ ......

½â¾ömySQLÕ¼ÓÃÄڴ泬´óÎÊÌâ

½â¾ömySQLÕ¼ÓÃÄڴ泬´óÎÊÌâ
ΪÁË×°mysql»·¾³²âÊÔ£¬×°ÉϺó·¢ÏÖÆô¶¯ºómysqlÕ¼ÓÃÁ˺ܴóµÄÐéÄâÄڴ棬´ï8°Ù¶àÕס£ÍøÉÏËÑË÷ÁËһϣ¬µÃµ½¸ßÈËÖ¸µãmy.ini¡£ÔÙҲû¼ûÔÙÏêϸµÄÁË..Ö»ºÃ´ò¿ªmy.iniÖðÐеĿУ¬ËäȻӢÎIJîÁ˵㣬²»¹ý¶àÉÙM»¹ÊÇ¿´µÃÃ÷µÄ^-^
 
¸ü¸ÄºóÈçÏ£º
innodb_buffer_pool_size=576M ->256M InnoDBÒýÇ滺³å ......

JAVAºÍPHP»ñÈ¡mysql×îºó²åÈëµÄ×ÔÔöidÖµ

phpºÍjavaͨÓÃsqlÓï¾ä·¨
SELECT max(id) from table
¸Ã·½·¨ÔÚ¶àÏ̵߳ÈÇé¿öÏ¿ÉÄÜ»áÔì³É²»ÕýÈ·¡£
javaÈýÖÖ·½·¨
1¡¢¸ù¾ÝpsµÄgetGeneratedKeys
PreparedStatement ps = conn.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS); //ºìÉ«Êǹؼü
ps.executeUpdate(); //Ö´Ðкó
ResultSet rs = ps.getGeneratedKeys ......

mysql µÄ ÄÚ´æ±íºÍÁÙʱ±í

1 ÄÚ´æ±íµÄ±í»ú¹¹»¹ÊÇÔÚÊý¾Ý¿âÖеģ¬Ö»ÊÇÊý¾Ýʱ·ÅÔÚÄÚ´æÖеġ£
2 ÄÚ´æ±íÖв»¿ÉÒÔʹÓÃTEXTºÍBLOBÀàÐ͵Ä×ֶΡ£
3 ÄÚ´æ±í¿ÉÒÔͨ¹ýmax_heap_table_size = 2048MÀ´¼Ó´óʹÓõÄÄÚ´æ¡£
1 ÁÙʱ±íµÄ±í»ú¹¹ºÍÊý¾Ý¶¼ÊÇ·ÅÔÚÄÚ´æÖеÄ
¾ßÌå¼ûÏ£º
ÄÚ´æ±íʹÓùþϣɢÁÐË÷Òý°ÑÊý¾Ý±£´æÔÚÄÚ´æÖУ¬Òò´Ë¾ßÓм«¿ìµÄËٶȣ¬Êʺϻº´æÖÐСÐÍÊý¾Ý¿ ......

mysql ±íÀàÐÍmyISAM £¬Innodb

¾ÍÎÒÖªµÀµÄÁ½¸öÇø±ð£º
myISAM  ²»Ö§³ÖÊÂÎñ
Innodb   Ö§³ÖÊÂÎñ
Èç¹ûÐÞ¸ÄmyISAM ΪInnodb£¬ÐèÒª°ÑÔ­À´µÄÊý¾ÝÏÈdump³öÀ´£¬Çå¿Õ±í£¬ÔÚÖØвåÈë
innodbÔÚ/etc/my.cfgµÄÅäÖÃΪ
innodb_data_home_dir = /var/lib/mysql/
innodb_data_file_path = ibdata1:2000M;ibdata2:10M:autoextend
innodb_log_group_hom ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ