Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best database field type for a URL

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?

like image 757
Jesse Hattabaugh Avatar asked Oct 20 '08 19:10

Jesse Hattabaugh


People also ask

What should be the data type for URL?

URL is a built-in datatype of Semantic MediaWiki that is used for the most common kinds of URLs, URNs, and URIs. It accepts almost any string and interprets it as a URL. The URL appears as a link in text and the Factbox. Technically speaking, e-mail addresses and even telephone numbers are also kinds of URLs.

Which data type allows storing URLs of websites or email address?

Hyperlink datatype in MS-Access is used to link websites, Email addresses, and files on a computer. ​

What data type would best store a username?

Yes, you can use varchar(15) datatype to store username. Varchar stores variable-length character string. it can require less storage than fixed-length types because it uses only as much space as it need.


1 Answers

  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)
like image 97
micahwittman Avatar answered Oct 04 '22 22:10

micahwittman