MySQL Workbench TEXT() Column Parameter

MySQL

I dont usually use MySQL workbench, I am trying to create a table with a text column by choosing TEXT(), however I am not sure what value I should put in between the '()'. If I leave it blank it gives me the error:

The given data type
TEXT()
contains errors and cannot be accepted. The previous value is kept instead.

I can put a number inside the parentheses but I wanted to know how it affects the column.

I could not find any answers online. I know how it affects things such as DATETIME() but not this data type.

Best Answer

In TEXT(M) M is an optional length. From the docs:

An optional length M can be given for this type. If this is done, MySQL creates the column as the smallest TEXT type large enough to hold values M characters long.

So you can use it to specify the maximum number of characters you anticipate for the field.

If you omit the parens - just TEXT - it will default to 65,535. Otherwise, if you supply the parens and a value it will default to the appropriate text type (TINYTEXT, TEXT, MEDIUMTEXT, LONGTEXT).

See here for a comparison with VARCHAR. One difference is that you cannot directly index a TEXT field, it requires a prefix.