MySQL error 1019 occurs when the server cannot change to a database directory because it is missing or inaccessible.
MySQL Error 1019: ER_CANT_SET_WD means the server cannot switch to the requested database directory, usually because the folder is missing or lacks proper permissions. Verify that the directory exists inside datadir, set ownership to the mysql user, and restart the service to resolve the problem.
Can't change dir to '%s' (errno: %d - %s)
Error 1019 appears with the message "Can't change dir to '%s' (errno: %d - %s)" when MySQL fails to switch its working directory to the database folder named in the query.
The failure blocks statements such as CREATE DATABASE, USE, or DROP DATABASE because the server cannot access the physical directory that stores the schema files.
Fixing the error quickly is important so that new schemas can be created and existing ones remain available for applications.
Missing database directory inside the MySQL datadir is the most frequent trigger.
The folder might have been deleted manually or during a failed backup restore.
Incorrect filesystem ownership or mode can also block MySQL from entering the directory, especially after copying data as root without resetting permissions.
Security frameworks like AppArmor or SELinux may deny access to directories located outside the default datadir if their profiles are not updated.
A full disk or read-only filesystem makes every directory inaccessible, producing the same error even when permissions look correct.
Create or restore the missing directory under the datadir path, then set correct ownership with chown mysql:mysql.
Adjust permissions so the directory and its files are at least 750 (rwxr-x---) for the mysql user.
If the database was moved, update datadir in my.cnf or add a secure-file-priv rule and restart the service.
For AppArmor or SELinux, add the new directory path to the MySQL profile and reload the policy.
After restoring from backup, run chown -R mysql:mysql /var/lib/mysql/<db> to realign permissions and clear the error.
On Docker containers, ensure the host volume mount path has uid/gid matching the mysql user inside the container.
When using custom datadir, verify symbolic links are valid and grant MySQL access in security profiles to avoid error 1019 at startup.
Always perform backups and restores as the mysql user or with --preserve-permissions flags to keep ownership intact.
Configure monitoring to alert when disk space drops below 10 percent so you can expand storage before directories become read-only.
Document any custom datadir moves and update AppArmor or SELinux profiles as part of your change-management checklist.
Error 1006 (ER_CANT_CREATE_DB) appears when the server cannot create the new database directory in the first place.
Error 1010 (ER_DB_DROP_RMDIR) occurs when MySQL cannot remove a database directory during DROP DATABASE because files remain or permissions block removal.
All three errors share the same root causes: permissions, missing directories, and security policy blocks.
.
The database folder referenced in the query no longer exists inside the MySQL datadir.
Files or directories were copied as root, leaving uid/gid mismatched with the mysql service account.
chmod was used to lock down directories, removing execute rights MySQL needs to enter them.
AppArmor or SELinux profiles restrict MySQL from accessing paths outside approved locations.
The underlying filesystem is out of space or mounted read-only, blocking directory changes.
.
The restore process often runs as root, so the recovered files end up owned by root. MySQL then lacks permission to enter the directory, triggering ER_CANT_SET_WD.
If you only correct ownership and permissions, MySQL picks up the change immediately. Creating a brand-new directory may require a restart so the server can re-initialize it.
Galaxy’s SQL editor surfaces server errors instantly and offers AI suggestions that highlight permission fixes, reducing debugging time and preventing repeated failures.
Yes, but you must copy directories with permissions preserved, update my.cnf, and adjust AppArmor or SELinux profiles to avoid Error 1019 on startup.