MySQL error "Specified key was too long; Max key length is 1000 bytes Solution _mysql

Source: Internet
Author: User
After the query to know, is the MySQL field set too long, so I put the length of these two fields changed a bit better.

When an index is indexed, the length of the database calculation key is to accumulate the char length of all the fields used by index and then multiply by the following proportion to no longer than the qualified key length 1000:
Latin1 = 1 byte = 1 character
Uft8 = 3 byte = 1 character
GBK = 2 byte = 1 character
For example to see more clearly, take GBK as an example:
CREATE UNIQUE INDEX ' Unique_record ' on reports (' Report_name ', ' report_client ', ' report_city ');
of which report_name varchar, report_client varchar, report_city varchar (200)
(+200) * 2 = 1200 > 1000, all will report 1071 error, as long as the report_city changed to varchar (100) Then the index can be successfully established.
If the table is a UTF8 character set, the index is still not built.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.