简体   繁体   中英

Unable to create column in MySQL database with datatype of TEXT

I'm creating a table to hold items from rss feeds and I need to create a column 'description'. I selected the datatype as TEXT with no limit set with no index on this column. This is the error I'm getting:

#1071 - Specified key was too long; max key length is 1000 bytes

If I select to index this column, I get this error message:

#1170 - BLOB/TEXT column 'description' used in key specification without a key length

Any length I specify for this column returns the first error I got. Can someone tell me what I'm doing wrong? Thanks!

UPDATE:

I'm using MySQL 5.0.4

Here is the query I'm using to create the table:

CREATE TABLE  `feed_items` (

`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`feed_id` INT NOT NULL COMMENT  '`feeds`.`id`',
`guid` VARCHAR( 255 ) NOT NULL ,
`publish_date` DATETIME NOT NULL ,
`update_of` INT NULL COMMENT  '`feed_items`.`id`',
`link` VARCHAR( 255 ) NOT NULL ,
`title` VARCHAR( 255 ) NOT NULL ,
`description` TEXT NOT NULL ,
`comments_link` VARCHAR( 255 ) NULL ,
INDEX (  `feed_id` ,  `guid` ,  `publish_date` ,  `update_of` ,  `title` )
) ENGINE = MYISAM

Even though it was from a while, this bug report seems to be what you are having an issue with: http://bugs.mysql.com/bug.php?id=4541

You may want to read through the comments on this bug, and see if they are referring to your situation, since it is hard to help without seeing what command you used to get this error, nor knowing which version of mysql.

UPDATE: Based on your query, you may want to remove this first:

INDEX (  `feed_id` ,  `guid` ,  `publish_date` ,  `update_of` ,  `title` )

Then, try doing:

INDEX (  `feed_id`)

When I see a long index like this I get suspicious.

Ideally you should index what you will be doing selects on, so unless you have

SELECT * FROM table WHERE feed_id=? AND guid=? AND publish_date=? AND update_of=? and title=?

then this index is useless. Since feed_id is a primary key you should just do

SELECT * FROM table where feed_id=?

as it will uniquely return one row.

So the index I have above would be what is needed. You may also want a separate index on title and perhaps publish_date.

Look at what queries you are writing, then you can determine where indexes should be. Indexes will get expensive as you add more rows, so you don't want to index too much, but indexing too little is useless, so that is why I suggest you look at the queries then decide where to have indexes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM