Home  >  Article  >  Database  >  What to do if 1071 error occurs in mysql

What to do if 1071 error occurs in mysql

coldplay.xixi
coldplay.xixiOriginal
2020-08-24 14:57:085258browse

Mysql 1071 error solution: This problem is caused by the key value field length being too long. MySQL supports the maximum length of a single key value in the database form cannot exceed 767 bytes. If the length is changed to 255, it will not work. problem, or there is no problem without using utf-8 format.

What to do if 1071 error occurs in mysql

The solution to the 1071 error in mysql:

This problem is caused by the key value field length being too long. MySQL supports that the maximum length of a single key value in a database form cannot exceed 767 bytes. If this length is exceeded, an error will be reported (see title name). Normally, no key value field will exceed this length. However, it should be noted that with the acceleration of globalization, the trend of database tables adopting UTF-8 format is becoming more and more obvious, which causes the length of varchar type fields to double, and the above problems may easily occur if you are not careful.

Assume that the following table definition exists:

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

When using UTF-8 format to create this table, the problem as shown in the title will occur. The key reason is that UTF-8 uses variable-length encoding and may use up to 3 bytes to represent 1 symbol. Therefore, for the name field in the above table, its actual length exceeds 767 bytes and reaches 768 bytes, and a problem occurs. If you change the length to 255 (767/3), there will be no problem, or if you do not use utf-8 format, there will be no problem.

Related learning recommendations: mysql tutorial

The above is the detailed content of What to do if 1071 error occurs in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn