Get the App
SLTechnology News&Howtos  ›  Database  › 

The solution to the 1071 error in mysql

Shulou Source: shulou.com Published: 2022-06-01 04:32:05 09月23日 Update

This article mainly introduces the solution to the 1071 error in mysql, which is very detailed and has a certain reference value. Interested friends must finish reading it!

Mysql has a 1071 error solution: the problem is caused by the length of the key value field is too long, mysql supports database forms the maximum length of a key value can not exceed 767 bytes, if the length is changed to 1071, there is no problem, or do not use the utf-8 format.

The solution to a 1071 error in mysql:

The problem is caused by the long length of the key value field. Mysql supports that the maximum length of a key value in a database form cannot exceed 767 bytes, beyond which an error is reported (see title name). In general, there is no key value field whose length exceeds that length. However, it should be noted that with the acceleration of globalization, the trend of database tables using UTF-8 format is becoming more and more obvious, which leads to a double increase in the length of varchar type fields, which is prone to the above problems.

Suppose the following table definition exists:

Create table test (name varchar (256) not null primary key, age int unsigned not null) engine = InnoDB

When the table is created in UTF-8 format, the problem appears as shown in the title. The key reason is that UTF-8 uses variable-length encoding, and it is possible to use up to 3 bytes to represent 1 symbol. So for the name field in the above table, the actual length exceeds 767 bytes to 768 bytes, and the problem arises. There is no problem if you change the length to 255 (767 prime 3) or not using the utf-8 format.

The above is all the contents of the solution to the 1071 error in mysql. Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Length problem field byte error format data database UTF-8 method maximum content method is made up of title form utf-8 one button support obvious Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Huawei MySQL Microsoft Shulou Information