简体   繁体   中英

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 

MySQL 5.0中VARCHAR的最大长度为65536,因此您不限于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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM