user198729
user198729

Reputation: 63636

What's the proper column type to save urls in MySQL?

I've been using varchar(300),but I've also noticed longer urls.

Upvotes: 4

Views: 6653

Answers (4)

Jess Stone
Jess Stone

Reputation: 677

As of now:

<< MySQL 5.0.3 use TEXT

or

>= MySQL 5.0.3 use VARCHAR(2083)

check this answer

Upvotes: 2

codaddict
codaddict

Reputation: 455020

Technically HTTP does not put a limit on the max length of a URL. Read this SO post.

So varchar will not be of help, You'll have to use TEXT

Upvotes: 3

Felix Kling
Felix Kling

Reputation: 816404

As you can see here, browsers can handle different URL lengths (and very long). So you should consider using text as data type.

Upvotes: 1

Quassnoi
Quassnoi

Reputation: 425361

Use TEXT, it's enough for every URL.

Note that with long URLs, you won't be able to create an index that covers the whole URL. If you need a UNIQUE index, you should calculate the URL hash, store the hash separately and index the hash instead.

Upvotes: 9

Related Questions