How to fix ERROR 1006: Can't create database in MySQL

MySQLINTERMEDIATEHIGHUpdated Dec 22, 2025· 132 views

MySQL throws error 1006 when it cannot create a new database due to file system permissions, disk space issues, or conflicting files. This typically requires checking write permissions on the MySQL data directory and ensuring sufficient disk space.

Quick fix

Fixes 1006

df -h
  1. Check available disk space
  2. Verify MySQL datadir permissions
  3. Check for conflicting files
  4. Review MySQL error log for detailed messages
mysql — error
df -h
ERROR 1006: Can't create database

What this error means

MySQL ERROR 1006 (ER_CANT_CREATE_DB) indicates that the MySQL server failed to create a new database directory. This is a file-system level error that occurs after MySQL validates the CREATE DATABASE statement syntax but before the database directory is created. The error means the server process either lacks write permissions in the data directory, there is insufficient disk space, a file already exists with the intended database name, or there are security policy restrictions (like SELinux) preventing directory creation. Unlike error 1007 which means the database already exists, error 1006 is more fundamental—MySQL cannot even attempt the operation. This usually indicates a configuration or environment problem rather than a user privilege issue.

Typical symptoms

  • CREATE DATABASE statement fails with "ERROR 1006"
  • Database creation fails for all databases, not just one
  • Error occurs even with sufficient user privileges (GRANT ALL)
  • Disk space appears available but database cannot be created
  • Permission denied messages in MySQL error log
  • Error persists after restarting MySQL service

Common causes

  1. MySQL datadir path lacks write permissions for the mysql user or process
  2. Disk space exhausted on the partition holding MySQL datadir
  3. File or directory already exists with the intended database name
  4. MySQL datadir or parent directory is corrupted
  5. SELinux, AppArmor, or container volume policies restrict write access
  6. InnoDB configuration points to non-existent or inaccessible directory
  7. Incorrect datadir setting in my.cnf or configuration

How to fix "ERROR 1006: Can't create database"

1Check available disk space

Verify that the partition containing the MySQL datadir has sufficient free space:

bash
df -h

Locate the MySQL datadir (default is /var/lib/mysql on Linux). If the partition shows less than 1GB free, you may need to delete old backups, archived logs, or expand the partition.

```bash
# Find actual MySQL datadir location
mysql -u root -p -e "SHOW VARIABLES LIKE 'datadir';"

2Verify MySQL datadir permissions

Check that the mysql user owns the datadir with proper permissions:

bash
ls -la /var/lib/mysql/

The directory should be owned by the mysql user and group with 755 or 750 permissions. If ownership is wrong, fix it:

bash
sudo chown -R mysql:mysql /var/lib/mysql
sudo chmod 755 /var/lib/mysql

For subdirectories, ensure they are also writable:

bash
sudo chmod 750 /var/lib/mysql/*
3Check for conflicting files

Verify no file exists with the name of the database you're trying to create:

bash
ls -la /var/lib/mysql/ | grep database_name

If a file (not directory) exists with that name, remove it:

bash
sudo rm /var/lib/mysql/database_name

Then retry the CREATE DATABASE statement.

4Review MySQL error log for detailed messages

The MySQL error log often contains more specific information about the failure:

bash
# Linux/Unix
sudo tail -50 /var/log/mysql/error.log

# Or check datadir for error log
sudo tail -50 /var/lib/mysql/hostname.err

Look for lines containing "ERROR" or "Permission denied" to identify the root cause (e.g., "Permission denied", "No space left on device").

5Check and fix SELinux or AppArmor policies (if applicable)

On systems with SELinux enabled, the MySQL context may restrict datadir access:

bash
# Check if SELinux is active
getenforce

# Restore proper SELinux context for MySQL
sudo restorecon -R /var/lib/mysql

For AppArmor (Ubuntu/Debian):

bash
# Check AppArmor status
sudo aa-status

# Reload AppArmor rules
sudo systemctl reload apparmor
6Verify MySQL datadir configuration

Ensure the my.cnf configuration points to the correct datadir:

bash
sudo grep datadir /etc/mysql/my.cnf /etc/mysql/mysql.conf.d/*.cnf

The path should exist and be accessible. If you changed the datadir recently, verify the new location has the correct ownership and permissions:

bash
sudo chown -R mysql:mysql /path/to/datadir
sudo chmod 755 /path/to/datadir
7Restart MySQL and test

After applying fixes, restart the MySQL service:

bash
sudo systemctl restart mysql

# Or for older systems:
sudo service mysql restart

Test the CREATE DATABASE statement:

bash
mysql -u root -p

CREATE DATABASE test_db;
SHOW DATABASES;
DROP DATABASE test_db;

If the test succeeds, your issue is resolved.

Advanced notes

On containerized deployments (Docker, Kubernetes), error 1006 often occurs when volumes are mounted read-only or with incorrect permissions. Ensure the volume is mounted with read-write access and the mysql user can write to it.

If you're using MySQL in a Docker container, ensure the volume mount has correct permissions:

bash
docker run -v /host/mysql/data:/var/lib/mysql --user mysql:mysql mysql

For AWS RDS, error 1006 is rare but can occur if the instance runs out of storage. Monitor the RDS instance storage and increase storage if needed.

On systemd-based systems, MySQL may run in a restricted environment. Check systemd service configuration:

bash
sudo systemctl status mysql
sudo journalctl -u mysql -n 50

If ProtectSystem or other hardening directives are enabled in /etc/systemd/system/mysql.service.d/, they may restrict datadir access. Adjust the service file accordingly.

Frequently asked questions

What does "1006" mean?
MySQL ERROR 1006 (ER_CANT_CREATE_DB) indicates that the MySQL server failed to create a new database directory. This is a file-system level error that occurs after MySQL validates the CREATE DATABASE statement syntax but before the database directory is created. The error means the server process either lacks write permissions in the data directory, there is insufficient disk space, a file already exists with the intended database name, or there are security policy restrictions (like SELinux) preventing directory creation.
How do I fix "1006"?
MySQL throws error 1006 when it cannot create a new database due to file system permissions, disk space issues, or conflicting files. This typically requires checking write permissions on the MySQL data directory and ensuring sufficient disk space.
What causes "1006"?
MySQL datadir path lacks write permissions for the mysql user or process Disk space exhausted on the partition holding MySQL datadir File or directory already exists with the intended database name
Is the "1006" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading