問題描述
我在 MySQL 中有一個(gè)消息表,用于記錄用戶之間的消息.除了典型的 id 和消息類型(所有整數(shù)類型),我需要將實(shí)際的消息文本保存為 VARCHAR 或 TEXT.我將前端限制設(shè)置為 3000 個(gè)字符,這意味著消息將永遠(yuǎn)不會(huì)插入到數(shù)據(jù)庫中超過此長(zhǎng)度.
I've got a messages table in MySQL which records messages between users. Apart from the typical ids and message types (all integer types) I need to save the actual message text as either VARCHAR or TEXT. I'm setting a front-end limit of 3000 characters which means the messages would never be inserted into the db as longer than this.
使用 VARCHAR(3000) 或 TEXT 是否有理由?僅僅編寫 VARCHAR(3000) 有點(diǎn)違反直覺.我已經(jīng)閱讀過 Stack Overflow 上的其他類似帖子,但如果能獲得特定于此類常見消息存儲(chǔ)的視圖會(huì)很好.
Is there a rationale for going with either VARCHAR(3000) or TEXT? There's something about just writing VARCHAR(3000) that feels somewhat counter-intuitive. I've been through other similar posts on Stack Overflow but would be good to get views specific to this type of common message storing.
推薦答案
TEXT
和BLOB
可以存儲(chǔ)在表外,而表只有一個(gè)指向?qū)嶋H存儲(chǔ)位置的指針.它的存儲(chǔ)位置取決于很多因素,例如數(shù)據(jù)大小、列大小、row_format 和 MySQL 版本.TEXT
andBLOB
may by stored off the table with the table just having a pointer to the location of the actual storage. Where it is stored depends on lots of things like data size, columns size, row_format, and MySQL version.VARCHAR
與表內(nèi)聯(lián)存儲(chǔ).VARCHAR
在大小合理時(shí)更快,權(quán)衡更快取決于您的數(shù)據(jù)和您的硬件,您希望使用您的數(shù)據(jù)對(duì)實(shí)際場(chǎng)景進(jìn)行基準(zhǔn)測(cè)試.VARCHAR
is stored inline with the table.VARCHAR
is faster when the size is reasonable, the tradeoff of which would be faster depends upon your data and your hardware, you'd want to benchmark a real-world scenario with your data.這篇關(guān)于MySQL:大 VARCHAR 與文本?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!