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

MYSQLÍâ¼ü(Foreign Key)µÄʹÓÃ


ÔÚMySQL 3.23.44°æ±¾ºó£¬InnoDBÒýÇæÀàÐ͵ıíÖ§³ÖÁËÍâ¼üÔ¼Êø¡£
Íâ¼üµÄʹÓÃÌõ¼þ£º
1.Á½¸ö±í±ØÐëÊÇ
InnoDB±í£¬MyISAM±íÔÝʱ²»Ö§³ÖÍâ¼ü£¨¾Ý˵ÒÔºóµÄ°æ±¾ÓпÉÄÜÖ§³Ö£¬µ«ÖÁÉÙÄ¿Ç°²»Ö§³Ö£©£»
2.Íâ¼üÁбØÐ뽨Á¢ÁËË÷Òý£¬MySQL
4.1.2ÒÔºóµÄ°æ±¾ÔÚ½¨Á¢Íâ¼üʱ»á×Ô¶¯´´½¨Ë÷Òý£¬µ«Èç¹ûÔÚ½ÏÔçµÄ°æ±¾ÔòÐèÒªÏÔʾ½¨Á¢£»
3.Íâ¼ü¹ØϵµÄÁ½¸ö±íµÄÁбØÐëÊÇÊý¾ÝÀàÐÍÏàËÆ£¬Ò²¾ÍÊÇ¿É
ÒÔÏ໥ת»»ÀàÐ͵ÄÁУ¬±ÈÈçintºÍtinyint¿ÉÒÔ£¬¶øintºÍcharÔò²»¿ÉÒÔ£»
Íâ¼üµÄºÃ´¦£º¿ÉÒÔʹµÃÁ½Õűí¹ØÁª£¬±£Ö¤Êý¾ÝµÄÒ»ÖÂÐÔºÍʵÏÖһЩ¼¶Áª²Ù×÷£»
Íâ¼üµÄ¶¨ÒåÓï·¨£º
[CONSTRAINT symbol] FOREIGN KEY [id] (index_col_name,
...)
    REFERENCES tbl_name (index_col_name, ...)
    [ON DELETE
{RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT}]
    [ON
UPDATE {RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT}]
¸ÃÓï·¨
¿ÉÒÔÔÚ CREATE TABLE ºÍ ALTER TABLE ʱʹÓã¬Èç¹û²»Ö¸¶¨CONSTRAINT
symbol£¬MYSQL»á×Ô¶¯Éú³ÉÒ»¸öÃû×Ö¡£
ON DELETE¡¢ON UPDATE±íʾʼþ´¥·¢ÏÞÖÆ£¬¿ÉÉè²ÎÊý£º
RESTRICT£¨ÏÞ
ÖÆÍâ±íÖеÄÍâ¼ü¸Ä¶¯£©
CASCADE£¨¸úËæÍâ¼ü¸Ä¶¯£©
SET NULL£¨Éè¿ÕÖµ£©
SET DEFAULT£¨ÉèĬÈÏÖµ£©
NO
ACTION£¨ÎÞ¶¯×÷£¬Ä¬Èϵģ©
¸ã¸öÀý×Ó£¬¼òµ¥ÑÝʾһÏÂʹÓã¬×ödageºÍxiaodiÁ½¸ö±í£¬´ó¸ç±íÊÇÖ÷¼ü£¬Ð¡µÜ±íÊÇÍâ¼ü£º
½¨±í£º
 1
CREATE
 
TABLE
 `dage` (
 2
  `id` 
int
(
11

NOT
 
NULL
 auto_increment,
 3
  `name` 
varchar
(
32

default
 
''
,
 4
  
PRIMARY
 
KEY
  (`id`)
 5
) ENGINE
=
InnoDB 
DEFAULT
 CHARSET
=
latin1£»
 6
 7
CREATE
 
TABLE
 `xiaodi` (
 8
  `id` 
int
(
11

NOT
 
NULL
 auto_increment,
 9
  `dage_id` 
int
(
11

default
 
NULL
,
10
  `name` 
varchar
(
32

default
 
''
,
11
  
PRIMARY
 
KEY
  (`id`),
12
  
KEY
 `dage_id` (`dage_i


Ïà¹ØÎĵµ£º

mysql Âý²éѯ·ÖÎö

轉×Ô»¨開µÄµØ·½
mysqlÓÐÒ»¸ö¹¦ÄܾÍÊÇ¿ÉÒÔlogÏÂÀ´ÔËÐеıȽÏÂýµÄsqlÓï¾ä£¬Ä¬ÈÏÊÇûÓÐÕâ¸ölogµÄ£¬ÎªÁË¿ªÆôÕâ¸ö¹¦ÄÜ£¬ÒªÐÞ¸Ämy.cnf»òÕßÔÚmysqlÆô¶¯
µÄʱºò¼ÓÈëһЩ²ÎÊý¡£
Èç¹ûÔÚmy.cnfÀïÃæÐ޸ģ¬ÐèÔö¼ÓÈçϼ¸ÐÐ
long_query_time = 1
log-slow-queries
=
log-queries-not-using-indexes
long_query_t ......

MySQLÐÐËøÉîÈëÑо¿

      ×öÏîĿʱÓÉÓÚÒµÎñÂß¼­µÄÐèÒª£¬±ØÐë¶ÔÊý¾Ý±íµÄÒ»Ðлò¶àÐмÓÈëÐÐËø£¬¾Ù¸ö×î¼òµ¥µÄÀý×Ó£¬Í¼Êé½èÔÄϵͳ¡£¼ÙÉè id=1 µÄÕâ±¾Êé¿â´æΪ 1 £¬µ«ÊÇÓÐ 2 ¸öÈËͬʱÀ´½èÕâ±¾Ê飬´Ë´¦µÄÂß¼­Îª :
Select restnum from book where id =1 ;
-- Èç¹û restnum ´óÓÚ 0 £¬Ö´ÐÐ update
Update boo ......

mysql hibernateÖ÷¼üÅäÖÃ

  ÔÚ½üÆÚµÄÏîĿά»¤¹¤×÷ÖУ¬Ê±³£³öÏÖÖ÷¼üÖظ´µÄÒì³£¡£¾­¹ýһϵÁÐ×ÊÁϵIJéѯ֮ºó£¬·¢ÏÖʱhibernateÓ³ÉäÎļþÅäÖÃÎÊÌâ¡£
  mysqlÌṩÖ÷¼ü“×Ô¶¯ÔöÁ¿”µÄÅäÖã¬Ö¸¶¨¸ÃÀàÐ͵ÄÖ÷¼ü£¬mysqlÄܹ»×Ô¶¯¼ÓÒ»¡£
  ÔÚhibernateÓ³ÉäÎļþÖУ¬¹ØÓÚÖ÷¼üµÄÅäÖò»ÄÜÊÇ
<generator class="increment"&g ......

mysql Âý²éѯ²éѯºÍÒýÆðÔ­Òò·ÖÎö

MySQLÓÐÒ»¸ö¹¦ÄܾÍÊÇ¿ÉÒÔlogÏÂÀ´ÔËÐеıȽÏÂýµÄsqlÓï¾ä£¬Ä¬ÈÏÊÇûÓÐÕâ¸ölogµÄ£¬ÎªÁË¿ªÆôÕâ¸ö¹¦ÄÜ£¬ÒªÐÞ¸Ämy.cnf»òÕßÔÚMySQLÆô¶¯µÄʱºò¼ÓÈëһЩ²ÎÊý¡£
Èç¹ûÔÚmy.cnfÀïÃæÐ޸ģ¬ÐèÔö¼ÓÈçϼ¸ÐÐ
long_query_time = 1
log-slow-queries =
log-queries-not-using-indexes
long_query_time ÊÇÖ¸Ö´Ðг¬¹ý¶à¾ÃµÄsql»á±»logÏÂÀ´£ ......

ÕÒ»Ømysql µÄroot ÃÜÂë

£¨1£©ÒÔubuntuµÄrootÓû§µÇ½
£¨2£©Í£Ö¹MYSQL·þÎñÆ÷£º
        /etc/init.d/mysql stop
£¨3£©Ìø¹ýÊÚȨ±íÖ´ÐÐMYSQL·þÎñÆ÷£º
       mysqld_safe --skip-grant-tables --skip-networking &
 (×¢£º²ÎÊý--skip-grant-tablesΪÌø¹ýÊÚȨ±í£»--sk ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ