How to Create Index on Long Data Type Field in MySQL

exceptionindexMySQL

I have a MySQL table with a long data type field:

`create_date` long NOT NULL,

I want to index it:

CREATE INDEX ix_logs_create_date ON `logs` (create_date) USING BTREE;

But I encounter the following exception:

Error Code: 1170. BLOB/TEXT column 'create_date' used in key specification without a key length 0.049 sec

Is it possible to index a long data type field? I have searched but cannot find anything discussing this particular issue

Best Answer

For long (mediumtext) you have to specify how much of the string you want to index. If you want the first 100 bytes in the column to be indexed:

CREATE INDEX ix_logs_create_date ON logs (create_date(100)) USING BTREE;

May I ask why you named a column of type long create_date?