What is the correct column type for storing URLs in MySQL?

I used varchar(300), but I also noticed longer URLs.

+3
source share
4 answers

Use TEXTit is enough for everyone URL.

Note that with long URLs you cannot create an index that covers the whole URL. If you need an index UNIQUE, you must calculate the hash URL, store the hash separately, and index the hash instead.

+7
source

Technically, HTTP does not limit the maximum length of a URL. Read this SO post.

varchar , TEXT

+2

As you can see here , browsers can handle different URL lengths (and very long). Therefore, you should use it textas a data type.

+1
source

For now:

<<MySQL 5.0.3 uses TEXT

or

> = MySQL 5.0.3 uses VARCHAR (2083)

check this answer

+1
source

Source: https://habr.com/ru/post/1731192/


All Articles