Best database field type for a URL

Jesse Hattabaugh picture Jesse Hattabaugh · Oct 20, 2008 · Viewed 248.4k times · Source

I need to store a url in a MySQL table. What's the best practice for defining a field that will hold a URL with an undetermined length?

Answer

micahwittman picture micahwittman · Oct 20, 2008
  1. Lowest common denominator max URL length among popular web browsers: 2,083 (Internet Explorer)
  1. http://dev.mysql.com/doc/refman/5.0/en/char.html
    Values in VARCHAR columns are variable-length strings. The length can be specified as a value from 0 to 255 before MySQL 5.0.3, and 0 to 65,535 in 5.0.3 and later versions. The effective maximum length of a VARCHAR in MySQL 5.0.3 and later is subject to the maximum row size (65,535 bytes, which is shared among all columns) and the character set used.
  1. So ...
    < MySQL 5.0.3 use TEXT
    or
    >= MySQL 5.0.3 use VARCHAR(2083)