When the mysql PRIMARY key is set to auto_increment, Duplicate PRIMARY key Duplicate entry & #39; xxx & #39; for key & #39; PRIMARY & #39;, duplicateentry appears in the concurrent performance test.

Source: Internet
Author: User

When the mysql PRIMARY key is set to auto_increment, the PRIMARY key repeat Duplicate entry 'xxx' for key 'Primary ', duplicateentry occurs during the concurrent performance test.

When the mysql PRIMARY key is set to auto_increment, the PRIMARY key repeat Duplicate entry 'xxx' for key 'Primary 'appears in the concurrent performance test'

Solution:

Add the setting innodb_autoinc_lock_mode = 0 in the [mysqld] segment of my. cnf.

At the same time, pay attention to increasing the number of active jdbc connections, such as setting jdbc. maxActive = 300, because setting innodb_autoinc_lock_mode = 0 may cause too many connections.

Note: This method only needs to be set during the concurrent performance test, because this method requires full table locking when inserting records, and the performance is poor, in normal production environments, you only need to use the default settings innodb_autoinc_lock_mode = 1. The official mysql documents are described as follows:


Http://dev.mysql.com/doc/refman/5.6/en/innodb-auto-increment-configurable.html

The meaning of the innodb_autoinc_lock_mode attribute is as follows:

1. innodb_autoinc_lock_mode = 0 ("traditional" lock mode)
This method is the same as before mysql5.1.22. It is characterized by "table-level locking" and poor concurrency.


2. innodb_autoinc_lock_mode = 1 ("consecutive" lock mode)
This method is the default method in the new version. It is recommended to use this method. The concurrency is relatively high and the feature is "consecutive". That is, the auto_increment id inserted in the same insert statement must be continuous.
In this mode:
"Simple inserts": directly obtain the number of inserts through the analysis statement, and assign enough auto_increment IDs at a time to lock the entire allocation process.
"Bulk inserts": because the number of inserts cannot be determined, use the same table-Level Lock as in the previous mode.
"Mixed-mode inserts": directly analyzes the statement to obtain the number of inserts in the worst case, and then allocates enough auto_increment IDs at a time to lock the entire allocation process. It should be noted that in this way, too many IDs will be allocated, resulting in "waste". For example, insert into t1 (c1, c2) VALUES (1, 'A'), (NULL, 'B'), (5, 'C'), (NULL, 'D'); five IDs will be allocated at a time, regardless of whether the User specifies part of the id; INSERT... On duplicate key update is assigned at a time, regardless of whether the duplicate key is inserted in the future or not.
Note: When the master mysql version is <5.1.22, slave mysql version> = 5.1.22, slave needs to set innodb_autoinc_lock_mode to 0 because the default innodb_autoinc_lock_mode is 1. For INSERT... On duplicate key update and insert into t1 (c1, c2) VALUES (1, 'A'), (NULL, 'B'), (5, 'C '), (NULL, 'D'); the execution results are different, and the actual environment usually uses INSERT... On duplicate key update.


3. innodb_autoinc_lock_mode = 2 ("interleaved" lock mode)
This mode is used to allocate a table instead of locking the table. It only locks the id allocation process. The difference from innodb_autoinc_lock_mode = 1 is that multiple IDs are not pre-allocated. This mode has the highest concurrency. However, in replication, when binlog_format is statement-based (SBR statement-based replication for short), there is a problem because one is allocated, so that when concurrent execution is performed, "Bulk inserts" will be allocated to other INSERT operations at the same time, and the master will be inconsistent (the slave database execution result is different from the master database execution result ), because binlog only records the start insert id.

Reference:

Http://biancheng.dnbcw.info/mysql/356243.html


An error occurred while setting the primary key and auto_increment in the existing MYSQL database.

Only one auto-increment column can be created. Generally, this column is a primary key. Do you want to avoid setting the auto_increment field as the primary key, or set more than one auto_increment field?

Each table can have only one such field, but cannot have multiple

Mysql database: Duplicate entry '0-119 'for key 1 is incorrect (0-119) is two primary keys.

Duplicate data
The prompt is a database error,
You said the data has been cleared,
I think the only answer is that you have a problem with the database Field settings. As a result, when you execute a program and write data to the database, duplicate data may conflict with the database, resulting in an error.

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.