×¢ÒâMysqlÊý¾Ý½Ø¶Ï
Beware of MySQL Data Truncation
http://www.mysqlperformanceblog.com/2009/02/07/beware-of-mysql-data-truncation/
±ÈÈ磺ÓÐÒ»¸ö±íaritcleºÍÁíÒ»¸ö±íarticle_comment£¬¹ØÁªÊÇarticleµÄid
CREATE TABLE `article` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(200) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB;
CREATE TABLE `article_comment` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`text` varchar(200) NOT NULL,
`article_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
KEY `art_id` (`article_id`),
CONSTRAINT `art_id` FOREIGN KEY (`article_id`) REFERENCES `article` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB;
set sql_mode='';
insert into article values(12345678901,'name1');
insert into article_comment(text,article_id) values('text1',12345678901);
insert into article_comment(text,article_id) values('text2',12345678902);
²é¿´Êý¾Ý£º
article±í
4294967295 name1
article_comment±í
1 text1 4294967295
2 text2 4294967295
´ÓÖпÉÒÔ¿´³ö£¬±¾À´µÚ¶þ¸ö²åÈëµÄÆÀÂÛÏë¹ØÁªÁíÒ»¸öÎÄÕ£¬µ«ÊÇÈ´¹ØÁªµ½Á˵ÚһƪÎÄÕ£¬ÕâÊÇÒòΪMysqlµÄData Truncation
show warningsÏÔʾ
Warning | 1265 | Data truncated for column 'article_id' at row 1
Õâ»áÔì³É£º
£¨1£©ÆÀÂÛ¹ØÁªµ½´íÎóµÄÎÄÕÂ
£¨2£©Í¬Ò»ÆªÎÄÕ¹ØÁªµ½Ðí¶àµÄÆÀÂÛ£¨Õâ»áÔì³ÉÐÔÄÜÎÊÌ⣩
ÔõÑù½â¾öÄØ£¿
set sql_mode='STRICT_ALL_TABLES';
insert into article_comment(text,article_id) values('text1',12345678903);
Õâ»á±¨´í£º
[SQL] insert into article_comment(text,article_id) values('text1',12345678903);
[Err] 1264 - Out of range value for column 'article_id' at row 1
Òò´ËÒ²¾Í±ÜÃâÁËÉÏÊöÎÊÌâ¡£
Ïà¹ØÎĵµ£º
<?php
/*
* Ãû³Æ : MySQLÊý¾Ý¿â»ù±¾²Ù×÷
* ×÷Õß : pjx
* °æ±¾ : v 2010/02/25 v 1.0
* ˵Ã÷ : ¸ÃÀàÓÃÓÚ¶ÔMySQL×öһЩ¼òµ¥µÄ²Ù×÷
* ʾÀý £º
* ʵÀý => $db = new DB_MYSQL($database),´ò¸ö$databaseÊý¾Ý¿â
* ²éѯÊý¾Ý¿â => $db->query($sql_str),²éѯ$sql_st ......
³õѧmysqlÎÒÒ²Åöµ½ÖÐÎÄ´æ´¢µÄÎÊÌ⣬ÒÔÏÂÊÇÎҵĽâ¾ö·½°¸£º
1.Ê×ÏÈÔÚ×Ö¶ÎÑ¡Ïîcolumn option Öн«×Ö¶Î×Ö·û¼¯column charsetÉèΪgb2312¡£
2.»¹ÐèÒªÔÚ±íÑ¡Ïîtable option ÖÐͬÑù½«charsetÉèÖÃΪgb2312.
3.×îºóÈç¹û»¹²»ÐУ¬¾ÍÔÚmysql°²×°Ä¿Â¼ÏÂÕÒµ½my.ini,ÕÒµ½ÒÔÏÂλÖãº
[mysql]
default-cha ......
ת×Ô£ºhttp://www.yayu.org/look.php?id=113
1£ºÔÚÖÕ¶ËÏ£ºmysql -V¡£
ÒÔÏÂÊÇ´úÂëƬ¶Î£º
[shengting@login ~]$ mysql -V
mysql Ver 14.7 Distrib 4.1.10a, for redhat-linux-gnu (i686)
2£ºÔÚmysqlÖУºmysql> status;
ÒÔÏÂÊÇ´úÂëƬ¶Î£º
mysql> status;
--------------
mysql ......
±¾ÎÄÀ´×Ô: ITÔËάר¼ÒÍø ×÷Õß: NetSeek ÈÕÆÚ: 2009-3-8 19:52 ÔĶÁ: 742 ÈË ´òÓ¡ ÊÕ²Ø DNS, Bind, DLZ, ÖÇÄÜ, MySQL ×÷Õß:NetSeek http://www.linuxtone.org
ÈÕÆÚ:2009-3-7 gmail:cnseek@gmail.com
ÍƼöÏÂÔØPDF°æ£¨·½±ã²éÔÄ):http://www.linuxtone.org/project/cdn/bind-dlz-view.pdf
¡¾Ìâ ¸Ù¡ ......