Mysql error: #1062 Duplicate entry '***' for key 1 Solution

Source: Internet
Author: User
Tags mysql manual

I changed the int type of id to bigint. In fact, it may be better to change it back. An error may occur during database backup.

This problem occurs during the testing of the developed website background system:
Invalid Query: Duplicate entry '000000' for key 1
SQL is: INSERT INTO 'kq _ new' ('title', 'autor', 'type', 'content', 'isdel', 'adate', 'range ', 'lang ') values ('donation activities', 'yuanying', '3', ", '0', NOW (), '2', 'cn ')
Because it was the first time that we encountered such a problem. GOOGLE gave us a bit of similar issues, and there were many similar solutions, that is, the repair table (repair) and MySQL repair Tool myisamchk. After a try, the problem persists.

Then I checked the data table structure:Copy codeThe Code is as follows: create table if not exists 'kq _ News '(
'Id' tinyint (3) not null auto_increment,
'Title' varchar (90) collate latin1_general_ci not null,
'Content' text collate latin1_general_ci not null,
'Adate' date not null,
'Isdel' tinyint (1) not null default '0 ′,
'Hits 'int (5) not null default '0 ′,
'Author' varchar (20) collate latin1_general_ci not null,
'Type' tinyint (1) not null default '1 ′,
'Lang 'varchar (2) collate latin1_general_ci not null,
'Range' tinyint (1) not null default '1 ′,
Primary key ('id ')
) ENGINE = MyISAM default charset = latin1 COLLATE = latin1_general_ci;

Finally, I realized that the type of the Self-incrementing field Id is wrong! Convert the data type!

Then I opened the MYSQL manual and found the description of TINYINT, SMALLINT, and INT types:

TINYINT [(M)] [UNSIGNED] [ZEROFILL]
A small integer. The signed range is-128 to 127, and the unsigned range is 0 to 255.

SMALLINT [(M)] [UNSIGNED] [ZEROFILL]
A small integer. The signed range is-32768 to 32767, And the unsigned range is 0 to 65535.

MEDIUMINT [(M)] [UNSIGNED] [ZEROFILL]
An integer of medium size. The signed range is-8388608 to 8388607, And the unsigned range is 0 to 16777215.

INT [(M)] [UNSIGNED] [ZEROFILL]
A normal integer. The signed range is-2147483648 to 2147483647, And the unsigned range is 0 to 4294967295.

INTEGER [(M)] [UNSIGNED] [ZEROFILL]
This is a synonym for INT.

BIGINT [(M)] [UNSIGNED] [ZEROFILL]
A large integer. The signed range is-9223372036854775808 to 9223372036854775807, And the unsigned range is 0
18446744073709551615.

So it turns out!
That's why other Invalid Query: Duplicate entry '000000' for key 1 errors on the Internet!

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.