What is the best way to store a URL value using MySQL?

5.5k views Asked by At

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 
3

There are 3 answers

4
pavium On BEST ANSWER

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

0
MarkR On

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.

3
AboutDev On

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.