9

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 
o.k.w
  • 25,490
  • 6
  • 66
  • 63
mii
  • 601
  • 1
  • 7
  • 8
  • Depending on your needs, you use URL shortening (IE: TinyURL) & store the shortened version. – OMG Ponies Nov 15 '09 at 03:37
  • 7
    @OMG Ponies: That's creating another external dependency. – o.k.w Nov 15 '09 at 03:41
  • 2
    255 is far too short as other people have pointed out. You'll need at least 2K if you go by the specs. The question is: what do you want to do with it? Just store as-is or treat as text? That will give you the type (BLOB or VARCHAR/TEXT) – dajobe Nov 15 '09 at 03:43
  • 1
    @OMG Ponies - That's a terrible, terrible idea. For example, do those TinyURLs last forever? – timdev Nov 15 '09 at 04:13
  • 1
    @timdev: tinyurl.com says right on its home page that a tiny URL "never expires." But fwiw I never use URL-shortening services. – Bill Karwin Nov 15 '09 at 04:16
  • @mii: You can use `SELECT VERSION();` in the MySQL client to see exactly what version you're using. Someone below said you're using 5.0.0, but I would be very surprised if you are. That'd be the first 5.x alpha release -- from December 2003! – Bill Karwin Nov 15 '09 at 04:20

3 Answers3

9

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

pavium
  • 14,808
  • 4
  • 33
  • 50
5

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
  • 1,923
  • 1
  • 23
  • 33
  • 4
    Since IE supports a max of 2,083 characters, you may decide to use VARCHAR(2083). :-) – AboutDev Nov 15 '09 at 03:31
  • @AboutDev: Now that we know it is for pre MySQL 5.0.3, that's not happening :( – o.k.w Nov 15 '09 at 03:42
  • 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 Nov 15 '09 at 03:53
0

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
  • 62,604
  • 14
  • 116
  • 151