MySQL varchar width to hold urls?
Accoridng to this SO Post the max length accpeted by IE is about 2048. However this seems way too big to set my varchar field in mysq开发者_StackOverflow社区l as most urls are typically smaller about 200 characters. Is this field meant to be set to the maximum or the average?
Don't worry -- you can still set the max size to 2048. This is just a maximum -- if a URL only takes 200 characters then that's all the DB engine will use.
If you use varchar, it won't matter. Check out the example from the MySQL docs.
If you decide to go with char, on the other hand, you will be storing a constant amount of data. Then you may wish to only store the domain -- a domain name is allowed to be up to 253 characters long. I suppose if you wanted to draw a line in the sand, that would probably be a reasonable one. You need to let the user know all of this BTW. Otherwise things could get bad.
精彩评论