1062 24
suggest change(taking a break) With the inclusion of those 4 error numbers, I think this page will have covered about 50% of the typical errors users get.
(Yes, this ‘Example’ needs revision.)
24 Can’t open file (Too many open files)
open_files_limit comes from an OS setting. table_open_cache needs to be less than that.
These can cause that error:
- Failure to
DEALLOCATE PREPAREin a stored procedure. - PARTITIONed table(s) with a large number of partitions and innodb_file_per_table = ON. Recommend not having more than 50 partitions in a given table (for various reasons). (When “Native Partitions” become available, this advice may change.)
The obvious workaround is to increase the OS limit: to allow more files, change ulimit, /etc/security/limits.conf, or sysctl.conf (kern.maxfiles and kern.maxfilesperproc), or the equivalent setting for your OS. Then increase open_files_limit and table_open_cache.
As of 5.6.8, open_files_limit is auto-sized based on max_connections, but it is OK to change it from the default.
1062 - Duplicate Entry
This error occurs mainly for the following two reasons.
- Duplicate value.
Error Code: 1062. Duplicate entry '12' for key 'PRIMARY'.
The primary key column is unique and will not accept a duplicate entry. Inserting a row whose primary-key value is already present in your table produces this error.
To solve this, set the primary key column as
AUTO_INCREMENT. When you insert a new row, omit the primary key column or insertNULLinto it.
CREATE TABLE userDetails(
userId INT(10) NOT NULL AUTO_INCREMENT,
firstName VARCHAR(50),
lastName VARCHAR(50),
isActive INT(1) DEFAULT 0,
PRIMARY KEY (userId) );
--->and now while inserting
INSERT INTO userDetails VALUES (NULL ,'John', 'Doe', 1);
- Unique column.
Error Code: 1062. Duplicate entry 'A' for key 'code'.
You may have declared a column UNIQUE. Inserting a new row with a value that already exists in that column produces this error.
To skip that row instead of raising an error, use
INSERT IGNOREinstead ofINSERT. If the new row does not duplicate an existing record, MySQL inserts it as usual. If it is a duplicate,IGNOREdiscards that row without generating an error. Duplicate rows are still not stored.
INSERT IGNORE INTO userDetails VALUES (NULL ,'John', 'Doe', 1);