04/12/06

Permalink 08:11:39 pm, by robertc Email , 586 words, 8264 views   English (UK)
Categories: Web Develop, Linux, Fedora / Red Hat Share on reddit Share on digg Share on del.icio.us Share on ma.gnolia.com Share on StumbleUpon

MySQL 4: Specified key was too long; max key length is 1000 bytes

I've been upgrading the intranet server at work today, previously it was running Red Hat 9.0 which even the Fedora Legacy Project will be dropping support for at the end of the year. So on Friday I installed Centos 4.4 on a nice new hard drive and I spent today copying across all the files from the old drive.

Mostly everything went without issues, but one of the things we have running on our intranet server is a WackoWiki for developer documentation. I'd done a backup of the pre-upgrade database with phpMyAdmin, which had been running on MySQL 3.23.

In my previous MySQL upgrade experiences I'd encountered some issues with character encoding - basically that the old database didn't have any, and newer versions of MySQL do. Up until now I've always just updated the relevant table definitions by hand, adding in unicode to the SQL and not really thought much about the wider implications. I was delighted to discover that phpMyAdmin 2.9.1.1 has an option on the import page for 'SQL compatibility mode', from which you can select 'MYSQL323', with the result that your old export files will now import without modification. Unfortunately, that's where I ran across the problem in the post title:

Specified key was too long; max key length is 1000 bytes

Some of the indexes in the WackoWiki database schema use a combination of three 250 character varchar columns. Because a unicode character can be up to three bytes long, MySQL tries to reserve the maximum space that could be required for the index - 3 x 250 x 3 bytes - which exceed the maximum allowed. There is an open defect about the issue on the MySQL website, with many comments from various disgruntled users.

I considered changing the keys so they'd fit, but it looked like a dangerous thing to do as far as the operation of WackoWiki was concerned, and I was worried I'd end up knee deep in PHP trying to fix all the problems. One of the comments on the bug report did guide me to the solution - Scott Lane posted that he set the index columns' collation to be latin1 so that it would work as it did on MySQL 3.23. Since the Wiki had been operating quite happily for more than three years on a database with no unicode support I figured I probably didn't have anything to lose by setting the whole database to use latin1_general_ci collation. I recreated the database and tried the import again and everything imported without errors :)

Which brings me to a D'Oh! moment. After some fannying around because the privileges got a bit mixed up with me dropping and recreating databases, I finally got to view our Wiki home page, and it looked very odd. None of the links were links - they all looked something like '??MyPages ==??'. I (correctly) surmised that I'd messed up somewhere with character encoding. At least it didn't take me too long to figure out my own stupid mistake: On the import page in phpMyAdmin, just below the file selection field, there's a 'Character set of the file:' select box which I'd been ignoring. By default this is set to UTF8, except, of course, the SQL file I'd exported from my non-unicode aware MySQL 3.23 database wasn't UTF8. This doesn't matter much for the common characters, because UTF8 and ASCII are compatible for the first 127 character points, but apparently it does matter very much for some of the characters used in WackoWiki markup. I re-imported with my import character set as latin1 and everything worked fine.

Trackback address for this post:

http://www.boogdesign.com/b2evo/th1srv/trackback.php/149

Comments, Trackbacks, Pingbacks:

Comment from: Sy Ali [Visitor] · http://jrandomhacker.info
Thanks for this post. I subscribed to that MySQL bug.

This is really horrible. So far I've been completely unable to import my own data. I'm using MediaWiki upgrading from a 4.0 to 5.0 database, and this is a nightmare. =(
PermalinkPermalink 15/08/07 @ 19:41
Well it seems that by deleting some misbehaving tables I was able to perform the import. I'm not entirely sure how/why it worked, but it did.

Instructions here

PermalinkPermalink 09/09/07 @ 02:29
Comment from: Sketchee [Visitor] · http://www.sketchee.com
Thanks! I was trying to import a database backup and I got the too long error. I changed the encoding to latin1 and it was fixed!
PermalinkPermalink 21/05/08 @ 06:16

Leave a comment:

Your email address will not be displayed on this site.
Your URL will be displayed.

Allowed XHTML tags: <p, ul, ol, li, dl, dt, dd, address, blockquote, ins, del, span, bdo, br, em, strong, dfn, code, samp, kdb, var, cite, abbr, acronym, q, sub, sup, tt, i, b, big, small>
(Line breaks become <br />)
(Set cookies for name, email and url)
(Allow users to contact you through a message form (your email will NOT be displayed.))

Hot Topics

Popular

boogdesign posts

Longer posts on standards based web design, portable web development and Linux, intermingled with some stuff on my other nerd interests.

Search

Syndicate this blog XML

  • RSS 0.92 Posts RSS 0.92 Comments
  • RSS 1.0 Posts RSS 1.0 Comments
  • RSS 2.0 Posts RSS 2.0 Comments
  • Atom Posts Atom Comments
What is RSS?

License info

Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 2.5 License.

powered by
b2evolution

get hCard