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
Too many connections
Connection
Column in field list is ambiguous
Query Syntax
Duplicate column name
DDL
Invalid default value for column
DDL
Multiple primary key defined
DDL
Host is not allowed to connect to this MySQL server
Access Control
Unknown system variable
Configuration
User has exceeded the max_user_connections resource
Connection
The used SELECT statements have a different number of columns
Query Syntax
Access denied; you need SUPER privilege for this operation
Access Control
Subquery returns more than 1 row
Query Syntax
Every derived table must have its own alias
Query Syntax
Data truncated for column
Data Integrity
Illegal mix of collations
Character Sets
FUNCTION or PROCEDURE does not exist
Stored Routines
Field doesn't have a default value
Data Integrity
Cannot delete or update a parent row: a foreign key constraint fails
Referential Integrity
Cannot add or update a child row: a foreign key constraint fails
Referential Integrity
Can't connect to local MySQL server through socket
Connection
Can't connect to MySQL server on host
Connection
MySQL server has gone away
Connection
Lost connection to MySQL server during query
Connection
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.