URL的最佳数据库字段类型 [英] Best database field type for a URL
问题描述
我需要在MySQL表中存储一个url。
I need to store a url in a MySQL table. What's the best practice for defining a field that will hold a URL with an undetermined length?
推荐答案
- 最好的做法是定义一个字段,
Lowest common denominator max URL length among popular web browsers: 2,083 (Internet Explorer)
http://dev.mysql.com/doc/refman/5.0/en/char.html
VARCHAR列中的值是可变长度字符串。长度可以指定为MySQL 5.0.3之前的0到255之间的值,以及5.0.3和更高版本中的0到65,535。 MySQL 5.0.3及更高版本中VARCHAR的有效最大长度受最大行大小(65,535字节,所有列共享)和所使用的字符集的限制。
http://dev.mysql.com/doc/refman/5.0/en/char.html
Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions. The effective maximum length of a VARCHAR in MySQL 5.0.3 and later is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.
所以...
< MySQL 5.0.3使用 TEXT
或
> = MySQL 5.0.3使用 VARCHAR(2083) >
So ...
< MySQL 5.0.3 use TEXT
or
>= MySQL 5.0.3 use VARCHAR(2083)
这篇关于URL的最佳数据库字段类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!