“不建议 MySQL 使用 Text 类型”,对于 Text 内容比较短小也不能用吗?
如果只是放一些短小 tinytext 、text 也会影响性能吗?
比如有个字段大约在 300~500 个字符,那要么用 varchar(512),或者直接用 text,这两种方式,性能差别会很大吗?
如果只是放一些短小 tinytext 、text 也会影响性能吗?
比如有个字段大约在 300~500 个字符,那要么用 varchar(512),或者直接用 text,这两种方式,性能差别会很大吗?
大部分使用 TEXT 和 BLOB 的时候都是要存储好几 KB 、MB 的内容,可以考虑清楚自己要存什么东西再定
对于索引,我猜可以通过索引字段内容的开头 xxx 字符处理,可以自行尝试一下
– 大于 varchar(255) 变为 `TINYTEXT`
– 大于 varchar(500) 变为 `TEXT`
– 大于 varchar(20000) 变为 `MEDIUMTEXT`
在某个地方看到的
https://stackoverflow.com/questions/25300821/difference-between-varchar-and-text-in-mysql
https://juejin.cn/post/6898479206087262222
For a column that has a data type of VARCHAR or one of the TEXT types, changes the data type as necessary to ensure that the new column is long enough to store as many characters as the original column. For example, a TEXT column has two length bytes, which store the byte-length of values in the column, up to a maximum of 65,535. For a TEXT column, each character requires a single byte, so the column can store up to 65,535 characters. If the column is converted to , each character might require up to three bytes, for a maximum possible length of 3 × 65,535 = 196,605 bytes. That length does not fit in a TEXT column’s length bytes, so MySQL converts the data type to MEDIUMTEXT, which is the smallest string type for which the length bytes can record a value of 196,605. Similarly, a VARCHAR column might be converted to MEDIUMTEXT. CONVERT TO CHARACTER SETlatin1utf8
https://dev.mysql.com/doc/refman/8.0/en/alter-table.html
Specifying the attribute for a character data type causes the column to be created as the corresponding binary data type: CHAR becomes BINARY, VARCHAR becomes VARBINARY, and TEXT becomes BLOB. For the ENUM and SET data types, this does not occur; they are created as declared. Suppose that you specify a table using this definition: CHARACTER SET binary
https://dev.mysql.com/doc/refman/8.0/en/silent-column-changes.html
In some cases, MySQL silently changes column specifications from those given in a CREATE TABLE or ALTER TABLE statement.
– If strict SQL mode is not enabled, a VARCHAR column with a length specification greater than **65535** is converted to TEXT.
而在数据类型确认下来后,如果没有 alter table,只对数据进行改动,数据类型是不会变化的