首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 數據庫知識 >  >> MySQL 資料庫 >> MySQL 綜合教學

MySQL 官方錯誤代碼完整對照表 (Server 1000-1499 / Client 2000-2054)

     編輯:MySQL 綜合教學

MySQL Error Code 完整參考手冊:Server 端 (1000-1499) 與 Client 端 (2000-2054)

源自 MySQL 官方源碼 include/errmsg.h (Server) 與 libmysql/errmsg.c (Client)。包含錯誤號、SQLSTATE、符號常量、英文消息模板。排查報錯時可直接檢索錯誤號定位原因。

Server 端錯誤碼精選 (高頻)

ErrorSQLSTATESymbolMessage
1004HY000ER_CANT_CREATE_FILECan't create file '%s' (errno: %d)
1005HY000ER_CANT_CREATE_TABLECan't create table '%s' (errno: %d)
1007HY000ER_DB_CREATE_EXISTSCan't create database '%s'; database exists
1008HY000ER_DB_DROP_EXISTSCan't drop database '%s'; database doesn't exist
1016HY000ER_CANT_OPEN_FILECan't open file: '%s' (errno: %d)
1021HY000ER_DISK_FULLDisk full (%s); waiting for someone to free space...
102223000ER_DUP_KEYCan't write; duplicate key in table '%s'
1032HY000ER_KEY_NOT_FOUNDCan't find record in '%s'
1037HY001ER_OUTOFMEMORYOut of memory; restart server and try again (need %d bytes)
104008004ER_CON_COUNT_ERRORToo many connections
104442000ER_DBACCESS_DENIED_ERRORAccess denied for user '%s'@'%s' to database '%s'
104528000ER_ACCESS_DENIED_ERRORAccess denied for user '%s'@'%s' (using password: %s)
104942000ER_BAD_DB_ERRORUnknown database '%s'
105042S01ER_TABLE_EXISTS_ERRORTable '%s' already exists
105142S02ER_BAD_TABLE_ERRORUnknown table '%s'
105442S22ER_BAD_FIELD_ERRORUnknown column '%s' in '%s'
106223000ER_DUP_ENTRYDuplicate entry '%s' for key %d
106442000ER_PARSE_ERRORYou have an error in your SQL syntax near '%s' at line %d
106742000ER_INVALID_DEFAULTInvalid default value for '%s'
1114HY000ER_RECORD_FILE_FULLThe table '%s' is full
1130HY000ER_HOST_NOT_PRIVILEGEDHost '%s' is not allowed to connect to this MySQL server
114642S02ER_NO_SUCH_TABLETable '%s.%s' doesn't exist
115308S01ER_NET_PACKET_TOO_LARGEGot a packet bigger than 'max_allowed_packet' bytes
1175HY000ER_UPDATE_WITHOUT_KEY_IN_SAFE_MODEYou are using safe update mode and tried to update a table without a WHERE that uses a KEY column
1205HY000ER_LOCK_WAIT_TIMEOUTLock wait timeout exceeded; try restarting transaction
121340001ER_LOCK_DEADLOCKDeadlock found when trying to get lock; try restarting transaction
1215HY000ER_CANNOT_ADD_FOREIGNCannot add foreign key constraint
122642000ER_USER_LIMIT_REACHEDUser '%s' has exceeded the '%s' resource (current value: %ld)
1290HY000ER_OPTION_PREVENTS_STATEMENTThe MySQL server is running with the %s option so it cannot execute this statement
1364HY000ER_NO_DEFAULT_FOR_FIELDField '%s' doesn't have a default value
1366HY000ER_TRUNCATED_WRONG_VALUE_FOR_FIELDIncorrect %s value: '%s' for column '%s' at row %ld
1449HY000ER_VIEW_FRM_NO_USERThe view '%s.%s' has no definer information (old table format)
145123000ER_ROW_IS_REFERENCED_2Cannot delete or update a parent row: a foreign key constraint fails (%s)
145223000ER_NO_REFERENCED_ROW_2Cannot add or update a child row: a foreign key constraint fails (%s)

Client 端錯誤碼精選 (高頻)

ErrorSymbolMessage
2000CR_UNKNOWN_ERRORUnknown MySQL error
2002CR_CONNECTION_ERRORCan't connect to local MySQL server through socket '%s' (%d)
2003CR_CONN_HOST_ERRORCan't connect to MySQL server on '%s' (%d)
2006CR_SERVER_GONE_ERRORMySQL server has gone away
2008CR_OUT_OF_MEMORYMySQL client ran out of memory
2013CR_SERVER_LOSTLost connection to MySQL server during query
2014CR_COMMANDS_OUT_OF_SYNCCommands out of sync; you can't run this command now
2020CR_NET_PACKET_TOO_LARGEGot packet bigger than 'max_allowed_packet' bytes
2026CR_SSL_CONNECTION_ERRORSSL connection error
2049CR_SECURE_AUTHConnection using old (pre-4.1.1) authentication protocol refused (client option 'secure_auth' enabled)
2054CR_NOT_IMPLEMENTEDThis feature is not implemented

使用建議

  • 應用層捕獲異常時,**務必記錄 Error Code + SQLSTATE**,而非僅記錄消息文本。
  • 針對 1205 (Lock Wait Timeout)、1213 (Deadlock)、1040 (Too Many Connections) 等高頻錯誤,建立自動重試/熔斷/告警機制。
  • 官方文檔在線版:MySQL 8.0 Error Message Reference,版本更新會有新增代碼。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved