开发者

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

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 


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜