What's the proper column type to save urls in MySQL?
I've been using varcha开发者_运维问答r(300)
,but I've also noticed longer urls.
Use TEXT
, it's enough for every URL
.
Note that with long URL
s, you won't be able to create an index that covers the whole URL
. If you need a UNIQUE
index, you should calculate the URL
hash, store the hash separately and index the hash instead.
Technically HTTP does not put a limit on the max length of a URL. Read this SO post.
So varchar
will not be of help, You'll have to use TEXT
As of now:
<< MySQL 5.0.3 use TEXT
or
>= MySQL 5.0.3 use VARCHAR(2083)
check this answer
As you can see here, browsers can handle different URL lengths (and very long). So you should consider using text
as data type.
精彩评论