Home:ALL Converter>What is the best datatype for storing URLs in a MySQL database?

What is the best datatype for storing URLs in a MySQL database?

Ask Time:2009-12-08T19:06:26         Author:sangeetha

Json Formatter

What is the best datatype for storing URLs in a MySQL database?

The ideal would be something that doesn't take up a lot of space but can easily handle variable length URLs.

Author:sangeetha,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/1866264/what-is-the-best-datatype-for-storing-urls-in-a-mysql-database
Gayasuddin Usmani :

We can use both Varchar(255) or BLOB. URL stored in text format in the database. ",
2018-10-09T06:15:33
Corey Ballou :

I recommend a VARCHAR field and the length is really personal opinion on what kind of URLs you are anticipating storing. You can get away with VARCHAR(255) without increasing the storage requirements for a VARCHAR field without penalty.\n\nCREATE TABLE example(\n id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,\n url varchar(125) \n);\n\n$url = 'http://www.google.com';\n$sql = 'INSERT INTO example SET url = ' . mysql_real_escape_string($url);\n",
2009-12-08T11:09:18
Abdul Wahid :

As the length of the web URL for different websites and pages are different thus it is appropriate to use data type with varying length.\n\ne.g if we want to store \"www.google.com\" in our database it will not be a problem but if we want to save link for search result from google like\n\n\"https://www.google.com/search?newwindow=1&safe=active&ei=nc1SXYS2EfvKgwfmkYsQ&q=Allah&oq=Allah&gs_l=psy-ab.3..0i71l8.65605.66784..67313...0.0..0.0.0.......6....1..gws-wiz.j8DsXUL6juY&ved=0ahUKEwjE-LTPi4DkAhV75eAKHebIAgIQ4dUDCAo&uact=5\"\n\nthan we will need lots of space for that.\n\nIf you construct a CHAR field large enough to hold this URL, you will be wasting a significant amount of space for almost every other URL being stored.\nA variable-length field lets you define a field length that can store the odd, long-length value while not wasting all that space for the common, short-length values. Variable-length text fields in MySQL use only as much space as necessary to store an individual value into the field.\n\nA VARCHAR(255) field that holds the string \"www.google.com\" for example, takes up only 15 bytes (1 byte for each character plus an extra byte to store the length). \nTIP: MySQL varies from the ANSI standard by not padding VARCHAR fields. Any extra spaces are removed from a value before it is stored. ",
2019-08-13T14:53:22
David Webb :

If by \"links\" you mean links to web pages, I'm guessing you want to store URLs.\n\nSince URLs are variable length strings the VARCHAR data type would seem the obvious choice.",
2009-12-08T11:08:34
Konamiman :

You can store URLs as simple strings, but be careful when comparing values since URLs may come in various forms while actually representing the same location (for example with/without the initial protocol identifier, or with/without a trailing slash).",
2009-12-08T11:10:31
Gayasuddin Usmani :

We can also take BLOB datatype in mysql Database for URL and file link",
2018-08-17T09:50:34
yy