MariaDB / MySQL Error Code Reference
Every significant MariaDB and MySQL error number explained — what it means, why it happens, and how to fix it. SQL trigger examples and fixes included for every entry.
⚙️ Error examples are AI-generated to help developers and are subject to the occasional error. Always verify against your specific version and setup.
Access denied for user to database
Access Control
Access denied for user (using password)
Access Control
No database selected
Connection
Column cannot be null
Constraint Violation
Unknown database
Schema
Table already exists
Schema
Unknown table
Schema
Unknown column in field list
Schema
Duplicate entry for key
Integrity Constraint Violation
You have an error in your SQL syntax
Syntax Error
Specified key was too long; max key length is 767 bytes
Schema
The table is full
Resource Limit
Column count doesn't match value count
Syntax Error
Table doesn't exist
Schema
Got a packet bigger than 'max_allowed_packet' bytes
Resource Limit
You are using safe update mode and tried to update a table without a WHERE using a KEY column
Safety
Lock wait timeout exceeded; try restarting transaction
Locking & Concurrency
Deadlock found when trying to get lock; try restarting transaction
Locking & Concurrency
Cannot add foreign key constraint
Schema
Cannot add or update a child row: a foreign key constraint fails
Integrity Constraint Violation
Cannot delete or update a parent row: a foreign key constraint fails
Integrity Constraint Violation
Out of range value for column
Data Truncation
Incorrect datetime value
Data Truncation
Incorrect integer value for column
Data Truncation
Data too long for column
Data Truncation
About This Reference
This MariaDB error code reference covers 25 of the most common error numbers encountered in production MariaDB and MySQL deployments. Each entry includes the official error number, SQLSTATE code, a minimal trigger SQL example, a verified fix with mechanism explanation, and sources from the official MariaDB documentation. Errors span access control, schema issues, constraint violations, locking, and data type mismatches.