Common SQL Errors

MySQL Error 1019: ER_CANT_SET_WD - Can't change dir – Fix Guide

Galaxy Team
August 5, 2025

MySQL error 1019 occurs when the server cannot change to a database directory because it is missing or inaccessible.

Sign up for the latest in common SQL errors from the Galaxy Team!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

What is MySQL error 1019 (ER_CANT_SET_WD)?

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.

Error Highlights

Typical Error Message

Can't change dir to '%s' (errno: %d - %s)

Error Type

Filesystem Permission Error

Language

MySQL

Symbol

ER_CANT_SET_WD

Error Code

1019

SQL State

Explanation

Table of Contents

What is MySQL error 1019 (ER_CANT_SET_WD)?

Overview

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.

What Causes This Error?

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.

How to Fix MySQL Error 1019

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.

Common Scenarios and Solutions

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.

Best Practices to Avoid This Error

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.

Related Errors and Solutions

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.

.

Common Causes

Missing directory

The database folder referenced in the query no longer exists inside the MySQL datadir.

Incorrect ownership

Files or directories were copied as root, leaving uid/gid mismatched with the mysql service account.

Filesystem permissions

chmod was used to lock down directories, removing execute rights MySQL needs to enter them.

Security policies

AppArmor or SELinux profiles restrict MySQL from accessing paths outside approved locations.

Disk full or read-only

The underlying filesystem is out of space or mounted read-only, blocking directory changes.

.

Related Errors

FAQs

Why does Error 1019 appear after a backup restore?

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.

Can I fix Error 1019 without restarting MySQL?

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.

How does Galaxy help prevent this error?

Galaxy’s SQL editor surfaces server errors instantly and offers AI suggestions that highlight permission fixes, reducing debugging time and preventing repeated failures.

Is it safe to move datadir to another disk?

Yes, but you must copy directories with permissions preserved, update my.cnf, and adjust AppArmor or SELinux profiles to avoid Error 1019 on startup.

Start Querying with the Modern SQL Editor Today!
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Check out some other errors

Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo