注意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
是以也就避免了上述問題。
相關文檔:
導入資料指定列
load data local infile 'D:\\service_func_utf8.txt' into table service_func fields terminated by '\t' (service_id, func_id1, func_id2, func_id3, func_id4, func_id5, func_id6);
MYSQL将查詢結果導出到檔案
select * from tablename into outfile '/tmp/test.txt';
MYSQL聯合主鍵
create  ......
初學mysql我也碰到中文存儲的問題,以下是我的解決方案:
1.首先在字段選項column option 中将字段字元集column charset設為gb2312。
2.還需要在表選項table option 中同樣将charset設定為gb2312.
3.最後如果還不行,就在mysql安裝目錄下找到my.ini,找到以下位置:
[mysql]
default-cha ......
一、表單送出亂碼解決方法
表單中含有中文送出亂碼,對于字母和數字則不會亂碼,我選用的字元集utf-8(以下同)。
1、在apache-tomcat-6.0.18\webapps\examples\WEB-INF\classes\filters目錄下找到檔案SetCharacterEncodingFilter.java 和RequestDumperFilter.java檔案,并将其複制到項目src ......
本文來自: IT運維專家網 作者: NetSeek 日期: 2009-3-8 19:52 閱讀: 742 人 列印 收藏 DNS, Bind, DLZ, 智能, MySQL 作者:NetSeek http://www.linuxtone.org
日期:2009-3-7 gmail:[email protected]
推薦下載下傳PDF版(友善查閱):http://www.linuxtone.org/project/cdn/bind-dlz-view.pdf
【題 綱� ......
http://book.51cto.com/art/200803/68118.htm
摘要:《深入淺出MySQL——資料庫開發、優化與管理維護》從資料庫的基礎、開發、優化、管理4方面對MySQL進行了詳細的介紹,其中每一部分都獨立成篇,每一篇又包括多個章節。本書面向實用,内容覆寫廣泛,講解由淺入深,适合于各個層次的讀者。
第20章 鎖問題
鎖是 ......