Newbie question, ridiculous.
I want each article to have an independent access statistics, and the access statistics information has a separate field.
One piece of access data is approximately 450 characters. Almost all are English numbers, only the IP address is in Chinese.
The text length is 65535, which is equivalent to about 145 lines. It feels like too little.
If you change it to mediumtext, it will feel too big and will not be used up, taking up space.
Is there any solution?
For access statistics, you should design a separate table. Setting it as a field is inconvenient to maintain. Let’s get a separate watch
Adjust the field appropriately. Aid is the article ID
mediumtext
比text
只多1 Byte
,如果你觉得这就算太大,用不完,占用空间
, then I can’t find a better wayThe author first needs to understand that text and longtext are variable-length field types.
This is the description in phpMyAdmin:
text: A text field that can store up to 65535 (2^16-1) bytes, and is stored in Use 2 bytes before the content to indicate the number of bytes of the content.
longtext: A maximum of 4294967295 bytes, or 4GB (2^32-1) text fields can be stored. When storing, use 4 bytes before the content to indicate the number of bytes of the content.
In other words, if you only store 1 character in a longtext field, the space occupied is only 4 bytes plus the number of bytes occupied by 1 character, instead of occupying 4 GB of storage space, 4 GB refers to the maximum value that the field can hold.
Finally, there are multiple quantities that are obviously related and need to be queried and counted. It is not recommended to stuff them all into one field. Things like uncertain session data (such as JSON strings) can be stored in a longtext field. For example, I Conversation table: