Identifies frequent MariaDB error messages and shows how to diagnose and fix them.
MariaDB raises ERROR 1054 (42S22): Unknown column 'x'
when a referenced column does not exist in the queried table or its aliases. Confirm spelling, case, and table alias, then rerun the statement.
-- Wrong
SELECT email FROM Customers c JOIN Orders o ON c.id = o.customer_id WHERE created_at > NOW();
-- Fix
SELECT c.email FROM Customers c JOIN Orders o ON c.id = o.customer_id WHERE o.order_date > NOW();
ERROR 1062 (23000): Duplicate entry
appears when an INSERT
or UPDATE
violates a UNIQUE or PRIMARY KEY constraint. Check for existing records or use INSERT IGNORE
, REPLACE
, or ON DUPLICATE KEY UPDATE
to handle duplicates safely.
INSERT INTO Customers (id, name, email)
VALUES (1, 'Ada', 'ada@example.com')
ON DUPLICATE KEY UPDATE email = VALUES(email);
ERROR 1215 (HY000): Cannot add foreign key constraint
usually means the parent and child columns differ in data type, length, charset, or collation. Align definitions, then recreate the constraint.
ALTER TABLE Orders
ADD CONSTRAINT fk_orders_customer
FOREIGN KEY (customer_id)
REFERENCES Customers(id);
ERROR 1205 (HY000): Lock wait timeout exceeded
happens when a transaction waits too long for a lock. Reduce lock scope, add indexes to speed scans, or split large transactions.
SET innodb_lock_wait_timeout = 10; -- shorten waits
COMMIT; -- release locks quickly
Use administrative commands to display diagnostics immediately after a failure.
SHOW ERRORS; -- full list in current session
SHOW WARNINGS; -- non-fatal issues
SELECT @@error_count; -- numeric count
Apply strict typing, add INDEXes on foreign keys, qualify columns with table aliases, validate input, wrap DDL in transactions, and monitor the error_log
for early detection.
Yes. Run SET FOREIGN_KEY_CHECKS = 0;
before bulk loads and reset to 1
afterward. Remember to validate data integrity once re-enabled.
Enable the general_log
or inspect the slow_query_log
. Combine with SHOW ERRORS
immediately after execution to correlate the statement with the message.
Identify blocking sessions with SHOW ENGINE INNODB STATUS
, then either optimize the offending query, add needed indexes, or kill the blocking connection if appropriate.