What is the difference between VARCHAR and TEXT in MySQL?

Answer

Both store variable-length string data, but with important differences: VARCHAR(n): stores up to n characters (max ~65,535 bytes per row limit); stored inline in the table row; can be fully indexed (entire value can be indexed); supports index prefix length; can have a DEFAULT value; supports UNIQUE constraint without prefix. Best for: strings with a known max length where indexing is needed (names, emails, slugs). TEXT (and TINYTEXT, MEDIUMTEXT, LONGTEXT): no length specified in column definition; stored out-of-row in separate storage (affects performance differently); TEXT columns cannot be fully indexed — only with a prefix: INDEX (description(100)); cannot have DEFAULT values; cannot be used in MEMORY engine tables. TEXT variants: TINYTEXT (255B), TEXT (64KB), MEDIUMTEXT (16MB), LONGTEXT (4GB). Recommendation: use VARCHAR for shorter strings (up to a few hundred characters) that you need to index, sort, or use in WHERE clauses; use TEXT for long bodies of text (blog posts, descriptions, comments) that don't need full indexing. MySQL stores values ≤255 bytes of VARCHAR in the row just like CHAR; longer values go to overflow pages like TEXT.