How long can a hyperlink be?
On my website, an user can insert a hyperlink in a text input field. The开发者_Python百科n, this link (a string) is stored in my database.
On MySQL, the field that contains the hyperlink string is TEXT
type, but I think its too long for this kind of information. Besides, VARCHAR(255)
is too short sometimes.
What's the best type/length to store a hyperlink? It would be nice to know how long a link can be.
There is no limit to how long a hyperlink can be. Browsers limit the amount of data a GET request can send with a hyperlink, but there is no limit on how long the actual link itself can be.
A standard TEXT field will be fine for storing links (you won't suffer a performance hit for using that field as opposed to the VARCHAR(255) field type, nor will you use extra memory, so there's really no reason not to use it.)
See: What is the maximum length of a URL in different browsers?
You could use VARCHAR(2048)
if you want a lower limit. There's nothing wrong with using TEXT
in terms of space though. In both cases they only use as much space as the text plus a few bytes to represent the length. See Data Type Storage Requirements for details.
As for whether or not you should pick VARCHAR
or TEXT
see: MySQL: Large VARCHAR vs. TEXT?
HTTP does not specify any limit to the length of URLs. However, webservers and browsers may put a limit.
I guess some old IE versions have a limit of just around 250 characters.
精彩评论