Itay Ganor Itay Ganor - 5 months ago 7
SQL Question

MYSQL - which variable type should I choose when hosting unknown URL?

I need to store a URL in one of my tables. Problem is, I don't know and can't assume its length.

I would like to know what variable type should I use (I was thinking about

TEXT
but i'm not sure because someone can submit a crazy-long URLs - they must not get cut)

Thanks!

Answer

Modern versions of MySQL support very long VARCHAR strings, so you can try with something like VARCHAR(2048) or use a TEXT field if you're concerned they could be even longer, that allows up to 64K characters.

Although there are historical reasons for keeping URLs relatively short, tradition holds they should be under 1500 characters, it's not uncommon to see some sites wildly exceed this. That being said, 64K should suffice and anything longer than that is a severe outlier.