SUMMARY:

This guide provides a step-by-step troubleshooting process for the MySQL error “[MY-013276] Failed to Set datadir” on Windows, which typically occurs after moving the data directory due to configuration or permission issues.

  • Check the Error Log: The first step is to examine the .err file for critical errors, such as invalid paths, file permission issues, or port conflicts that prevent the server from starting.
  • Validate the my.ini Configuration: Ensure the my.ini file has the correct paths for basedir and datadir using forward slashes (/) or escaped backslashes (\\) and that the data directory has been properly initialized.
  • Test MySQL Manually: Run mysqld.exe directly from the command line with the --defaults-file flag to get detailed console output that can pinpoint the exact configuration or directory error without involving the Windows service.

By systematically validating your configuration and permissions, you can quickly identify and fix the root cause of the datadir failure

What Causes the MySQL “Failed to Set datadir” Error?

If you’ve changed the datadir location in the my.ini file and restarted the MySQL service on a Windows server, you may encounter this error:

Error:

[ERROR] [MY-013276] [Server] Failed to set datadir to 'C:\Program Files\MySQL\MySQL Server 8.0\data\' (OS errno: 2 - No such file or directory)

Like me, you might be wondering why mysqld is trying to set the datadir in the default location. These are the first steps to finding that out.

Step-by-Step Troubleshooting

1. Check the Error Log

Most critical errors — including permission issues or invalid paths — are logged to the .err file defined in your my.ini.

Open that file and look for:

  • File permission issues
  • Invalid datadir
  • Port conflicts
  • Incorrect paths

2. Validate my.ini Configuration

Ensure your my.ini file is clean, valid, and points to the correct directories.

Things to check:

  • basedir and datadir exist
  • Data directory has been initialized using mysqld –initialize (or –initialize-insecure)
  • You’ve used forward slashes / or properly escaped backslashes \\ in paths
  • System variables are not listed more than once. The MySQL Server will recognize the last value referenced.

3. Test MySQL Without Installing the Service

Before reinstalling or restarting the Windows service, test MySQL manually to see direct output:

Example uses a generic location for the datadir. Edit the command as necessary.

"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqld.exe" --defaults-file="C:\new\path\my.ini"

If your config or directory setup is invalid, this command will output a detailed error in the console — no guesswork required.

Encountering other MySQL issues? Check out our other MySQL blogs or contact us!