Error
Error Code: 1005

MariaDB Error 1005: Table Creation Failure

📦 MariaDB
📋

Description

This error indicates that MariaDB was unable to create a new table as requested. It typically occurs during schema changes, application deployments, or when manually executing `CREATE TABLE` statements. The specific reason for the failure is often detailed by the `errno` code appended to the message.
💬

Error Message

Can't create table '%s' (errno: %d)
🔍

Known Causes

4 known causes
⚠️
Insufficient User Privileges
The MariaDB user attempting to create the table lacks the necessary `CREATE` privilege for the specified database or schema.
⚠️
Out of Disk Space
The server's storage device where the MariaDB data directory resides has run out of available disk space, preventing new file creation.
⚠️
Invalid Table Definition
The `CREATE TABLE` statement contains syntax errors, invalid column types, or violates database constraints (e.g., foreign key issues, duplicate column names).
⚠️
File System or Directory Issues
Problems with the underlying operating system's file system, such as incorrect directory permissions for the MariaDB data directory, or a read-only file system.
🛠️

Solutions

4 solutions available

1. Fix Foreign Key Constraint Issues medium

Most common cause - resolve FK reference problems

1
Check the detailed error message
SHOW ENGINE INNODB STATUS;
2
Verify referenced table and column exist
SHOW CREATE TABLE parent_table_name;
3
Ensure column types match exactly
-- Parent and child FK columns must have identical types
-- Example: both must be INT UNSIGNED, not INT vs INT UNSIGNED
CREATE TABLE child (
    id INT PRIMARY KEY,
    parent_id INT UNSIGNED,  -- Must match parent.id type exactly
    FOREIGN KEY (parent_id) REFERENCES parent(id)
);
4
Check that referenced column has an index
SHOW INDEX FROM parent_table_name;

2. Grant CREATE Privilege easy

Ensure user has permission to create tables

1
Check current user privileges
SHOW GRANTS FOR CURRENT_USER();
2
Grant CREATE privilege
GRANT CREATE ON database_name.* TO 'username'@'host';
FLUSH PRIVILEGES;
3
For all schema modification privileges
GRANT CREATE, ALTER, DROP, INDEX ON database_name.* TO 'username'@'host';
FLUSH PRIVILEGES;

3. Free Disk Space easy

Ensure sufficient storage for new table files

1
Check disk space
df -h /var/lib/mysql
2
Find largest tables to potentially archive
SELECT table_schema, table_name,
       ROUND(data_length/1024/1024, 2) AS data_mb,
       ROUND(index_length/1024/1024, 2) AS index_mb
FROM information_schema.tables
ORDER BY data_length DESC
LIMIT 20;
3
Optimize tables to reclaim space
OPTIMIZE TABLE database_name.large_table_name;

4. Fix Table Definition Errors medium

Correct syntax and constraint issues in CREATE TABLE

1
Check for duplicate column names
-- Wrong: duplicate column
CREATE TABLE test (id INT, id INT);

-- Correct: unique column names
CREATE TABLE test (id INT, user_id INT);
2
Verify storage engine is available
SHOW ENGINES;
3
Check for row size limits (InnoDB max ~8KB per row)
-- If you have many VARCHAR columns, consider using TEXT
-- or enable innodb_file_format=Barracuda with ROW_FORMAT=DYNAMIC
4
Validate charset and collation compatibility
SHOW CHARACTER SET;
SHOW COLLATION WHERE Charset = 'utf8mb4';
🔗

Related Errors

5 related errors