views:

557

answers:

3

I was thinking of storing URL values in my database but I know some URL's sometimes get ridiculously long. I think my MySQL Database is Version 5.0.

I was thinking of using.

VARCHAR(255)

but this will only work for so long. So should I use.

TEXT
+5  A: 

The maximum length of a VARCHAR in MySQL 5.0 is 65536, so you're not limited to 255.

pavium
Yea, `TEXT` is kind of an overkill
o.k.w
I thought it was only available in in 5.0.3 and later versions
mii
@mii: I see, you are using 5.0.0. Tough luck!
o.k.w
@mii, yes, it's bad luck. BTW, when you said you use MySQL 5.0, I think most readers would assume you meant a later version than 5.0.0 Maybe you have an incentive to upgrade. ;-)
pavium
+4  A: 

Maximum URL lengths are different for different browsers. Your best bet is to decide on the length you wish to support and then set the size on a VARCHAR if it will fit VARCHAR max length. If you need to use TEXT, ask why.

AboutDev
Since IE supports a max of 2,083 characters, you may decide to use VARCHAR(2083). :-)
AboutDev
@AboutDev: Now that we know it is for pre MySQL 5.0.3, that's not happening :(
o.k.w
Yep. A possible solution if you really need to support so many characters is to make a separate URL table and store the elements of the URL in there as separate columns...such as the server, yadda yadda.
AboutDev
A: 

Do not use 5.0.0, or indeed any .0 version. That wasn't even released as GA.

The answer to your question depends if, or how much, you want to index it. You'll probably want to index it but you can use a prefix index which will save loads of space in the index and be almost as selective. The downside is that if you wanted to sort the URLs into order, a prefix index won't do it so it will need a filesort.

MarkR