Common SQL Errors

MySQL Error 1014: ER_CANT_GET_WD - Can't Get Working Directory – Fix and Prevent

Galaxy Team
August 5, 2025

The server cannot determine its current working directory, usually due to missing folders or insufficient OS permissions, so startup or file operations fail.

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 1014 (ER_CANT_GET_WD)?

MySQL Error 1014: ER_CANT_GET_WD occurs when the server cannot get its working directory because the path is missing or permissions are wrong. Confirm the datadir exists and grant the MySQL user read and execute rights to resolve the problem.

Error Highlights

Typical Error Message

Can't get working directory (errno: %d - %s)

Error Type

System Error

Language

MySQL

Symbol

ER_CANT_GET_WD

Error Code

1014

SQL State

Explanation

Table of Contents

What is MySQL Error 1014 (ER_CANT_GET_WD)?

MySQL Error 1014 with condition ER_CANT_GET_WD and SQLSTATE HY000 means the server process failed to obtain its current working directory. The error appears during startup, INSTALL PLUGIN, or other file-based operations and immediately halts the requested action.

The operating system call getcwd or chdir returns an error because the directory does not exist, is unreachable, or the MySQL service account lacks read and execute permissions.

The server exits or refuses the statement until the environment issue is corrected.

What Causes This Error?

Missing or moved datadir, base directory, or plugin directory is the most common trigger. If the folder referenced by the mysqld --basedir or --datadir option was deleted, renamed, or on an unmounted volume, MySQL cannot resolve the path.

Incorrect file system permissions also raise Error 1014.

The MySQL OS user must have at least execute rights on every folder in the path to call getcwd successfully.

Security layers such as SELinux, AppArmor, or Windows UAC can block directory access and cause the same failure even when Unix permissions look correct.

Containerized deployments sometimes start mysqld in a directory that disappears after build, leaving the process without a valid working directory.

How to Fix MySQL Error 1014

Confirm the failing path.

Review mysqld logs or the message that follows the errno placeholder, then verify the directory exists on disk.

Grant the MySQL user ownership or at minimum rwx on the directory. On Linux run: chown -R mysql:mysql /var/lib/mysql and chmod 750 /var/lib/mysql. Restart the service and watch the log.

Update configuration files if paths changed. Edit my.cnf to point datadir, basedir, plugin_dir, and tmpdir to valid folders.

After saving, reload the daemon and restart mysqld.

For SELinux, create a policy module or run chcon -t mysqld_db_t /var/lib/mysql -R.

On AppArmor, adjust /etc/apparmor.d/usr.sbin.mysqld to allow the directory.

Common Scenarios and Solutions

Container rebuild removed the workdir - mount the host volume at the same mount point or add WORKDIR /var/lib/mysql in the Dockerfile.

Windows service runs as Local Service without rights - open Services, Properties, Log On, and switch to the dedicated MySQL user that owns the data directory.

Deployment moved datadir - create a symlink ln -s /mnt/data/mysql /var/lib/mysql or update my.cnf accordingly and restart.

Best Practices to Avoid This Error

Store datadir on a fixed, persistent path and add integrity checks in deployment scripts to verify directory presence before restarting MySQL.

Use Galaxy's path validation.

When you open my.cnf in the Galaxy SQL editor, the built-in linter flags nonexistent directories and highlights permission risks before you apply the configuration.

Monitor MySQL startup logs with a centralized tool and set alerts for "ER_CANT_GET_WD" so you can act before production traffic is impacted.

Related Errors and Solutions

Error 1010 ER_DB_DROP_EXISTS indicates an attempt to drop a database that still exists.

Verify DROP DATABASE statement.

Error 1049 ER_BAD_DB_ERROR fires when connecting to a database name that does not exist. Create the database or correct the name.

Error 1017 ER_CANT_READ_DIR refers to directory read failures often linked to permission problems like Error 1014. Troubleshooting steps are similar: check folder existence and rights.

.

Common Causes

Missing directory

The path defined in datadir, basedir, tmpdir, or plugin_dir does not exist because it was deleted, renamed, or is on an unmounted volume.

Insufficient permissions

The MySQL operating system user lacks execute permission on one or more folders in the path, preventing getcwd from resolving the current directory.

Security policies

SELinux, AppArmor, or antivirus software blocks access to the working directory despite correct Unix permissions.

Environment mismatch

Container images or scripts start mysqld in a directory that disappears after build, leaving the process with no valid working directory.

.

Related Errors

FAQs

Does Error 1014 always stop MySQL from starting?

Yes. If mysqld cannot obtain its working directory, initialization halts and the server fails to start until the path issue is fixed.

Can I solve Error 1014 using only SQL commands?

No. This error stems from the operating system, so you must fix file paths or permissions outside MySQL, then restart the service.

Will changing datadir erase my data?

Moving datadir does not delete data, but you must copy files to the new location and adjust permissions before restarting MySQL.

How does Galaxy help with this problem?

Galaxy's SQL editor linter checks configuration files for invalid paths and highlights risks, preventing Error 1014 before deployment.

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