4

I've been using varchar(300),but I've also noticed longer urls.

user198729
  • 61,774
  • 108
  • 250
  • 348

4 Answers4

9

Use TEXT, it's enough for every URL.

Note that with long URLs, you won't be able to create an index that covers the whole URL. If you need a UNIQUE index, you should calculate the URL hash, store the hash separately and index the hash instead.

Quassnoi
  • 413,100
  • 91
  • 616
  • 614
  • What do you mean by "it"? `TEXT` is a standard and supported feature, `MD5` hashing is too (and `MySQL` contains a function for calculating the hash). – Quassnoi Feb 03 '10 at 12:33
  • That's how I do it, as well. Also, it's worth considering benchmarking various hash functions, I chose MD5, since it's slightly faster than all the others, but MD4. – Nikola Kotur Feb 03 '10 at 12:36
  • Seems there is no `MD4` in PHP. – user198729 Feb 03 '10 at 12:41
  • @Nikola: `MySQL` lacks `MD4` supports, but if it did, it would certainly be a preferred hash function. – Quassnoi Feb 03 '10 at 12:43
  • @Quassnoi, yes, you're right, but I don't hash in MySQL (it showed slower), YMMV. @eugene y, hash is one of the columns in the table. – Nikola Kotur Feb 03 '10 at 12:55
  • @unknown googler, yes it does, via Hash cryptography extension, do print_r(hash_algos()). – Nikola Kotur Feb 03 '10 at 13:01
3

Technically HTTP does not put a limit on the max length of a URL. Read this SO post.

So varchar will not be of help, You'll have to use TEXT

Community
  • 1
  • 1
codaddict
  • 445,704
  • 82
  • 492
  • 529
  • 1
    The post you have referenced states that urls have a max length of 2048. How you state "Technically HTTP does not put a limit on the max length of a URL"? – Mehrdad Shokri Mar 20 '18 at 06:01
2

As of now:

<< MySQL 5.0.3 use TEXT

or

>= MySQL 5.0.3 use VARCHAR(2083)

check this answer

Community
  • 1
  • 1
Jess Stone
  • 677
  • 8
  • 21
1

As you can see here, browsers can handle different URL lengths (and very long). So you should consider using text as data type.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143