MySQL error "Specifiedkeywastoolong; maxkeylengthis100

Source: Internet
Author: User
The Specifiedkeywastoolong; maxkeylengthis1000bytes error occurs when you set a unique index for a certain two fields in the database today.

The Specified key was too long; max key length is 1000 bytes error occurs when you set a unique index for a certain field in the database today.

After query, I know that the Mysql field is too long, so I just changed the length of the two fields.

When an Index is created, the length of the key calculated by the database is to accumulate the char length of all the fields used by the Index, and then multiply by the following proportion, the length of the key cannot exceed 1000:
Latin1 = 1 byte = 1 character
Uft8 = 3 byte = 1 character
Gbk = 2 byte = 1 character
For example, you can see more clearly. Take GBK as an example:
Create unique index 'unique _ record' ON reports ('report _ name', 'Report _ client', 'Report _ City ');
Report_name varchar (200), report_client varchar (200), report_city varchar (200)
(200 + 200 + 200) * 2 = 1200> 1000. If the report_city is changed to varchar (1071), the index can be created successfully.
If the table is a UTF8 character set, the index cannot be created.

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.