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.
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.
Verify that the partition containing the MySQL datadir has sufficient free space:
df -hLocate 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';"
Check that the mysql user owns the datadir with proper permissions:
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:
sudo chown -R mysql:mysql /var/lib/mysql
sudo chmod 755 /var/lib/mysqlFor subdirectories, ensure they are also writable:
sudo chmod 750 /var/lib/mysql/*Verify no file exists with the name of the database you're trying to create:
ls -la /var/lib/mysql/ | grep database_nameIf a file (not directory) exists with that name, remove it:
sudo rm /var/lib/mysql/database_nameThen retry the CREATE DATABASE statement.
The MySQL error log often contains more specific information about the failure:
# Linux/Unix
sudo tail -50 /var/log/mysql/error.log
# Or check datadir for error log
sudo tail -50 /var/lib/mysql/hostname.errLook for lines containing "ERROR" or "Permission denied" to identify the root cause (e.g., "Permission denied", "No space left on device").
On systems with SELinux enabled, the MySQL context may restrict datadir access:
# Check if SELinux is active
getenforce
# Restore proper SELinux context for MySQL
sudo restorecon -R /var/lib/mysqlFor AppArmor (Ubuntu/Debian):
# Check AppArmor status
sudo aa-status
# Reload AppArmor rules
sudo systemctl reload apparmorEnsure the my.cnf configuration points to the correct datadir:
sudo grep datadir /etc/mysql/my.cnf /etc/mysql/mysql.conf.d/*.cnfThe path should exist and be accessible. If you changed the datadir recently, verify the new location has the correct ownership and permissions:
sudo chown -R mysql:mysql /path/to/datadir
sudo chmod 755 /path/to/datadirAfter applying fixes, restart the MySQL service:
sudo systemctl restart mysql
# Or for older systems:
sudo service mysql restartTest the CREATE DATABASE statement:
mysql -u root -p
CREATE DATABASE test_db;
SHOW DATABASES;
DROP DATABASE test_db;If the test succeeds, your issue is resolved.
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:
docker run -v /host/mysql/data:/var/lib/mysql --user mysql:mysql mysqlFor 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:
sudo systemctl status mysql
sudo journalctl -u mysql -n 50If ProtectSystem or other hardening directives are enabled in /etc/systemd/system/mysql.service.d/, they may restrict datadir access. Adjust the service file accordingly.
EE_WRITE (3): Error writing file
How to fix "EE_WRITE (3): Error writing file" in MySQL
CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters
How to fix "CR_PARAMS_NOT_BOUND (2031): No data supplied for parameters" in MySQL
CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed
How to fix "CR_DNS_SRV_LOOKUP_FAILED (2070): DNS SRV lookup failed" in MySQL
ERROR 1146: Table 'database.table' doesn't exist
How to fix "ERROR 1146: Table doesn't exist" in MySQL
ERROR 1040: Too many connections
How to fix "ERROR 1040: Too many connections" in MySQL