How to fix MySQL can't create test file error

Learn how to fix MySQL startup error can't create test file

Posted on November 14, 2021

When you’re starting your MySQL server after installation, you may receive a warning message saying that MySQL can’t create test file as follows:

[Warning] Can't create test file 
D:\programs\MySQL\MySQL Server 8.0\data\Winz.lower-test

The warning above would then cause your MySQL server to fail with the following message:

[ERROR] failed to set datadir to D:\programs\MySQL\MySQL Server 8.0\data
[ERROR] Aborting
[Note] Binlog end
[Note] mysqld: Shutdown complete

The MySQL test file is actually something that MySQL write to the datadir folder during startup to check if MySQL can write files to that folder.

The real problem of the error above comes from the actual log marked with [ERROR], which is MySQL failed to set datadir to D:\programs\MySQL\MySQL Server 8.0\data

The datadir is where MySQL keeps all your database information, so it needs to be set on an existing folder/ directory.

When you encounter this error, you can resolve it by checking if the datadir directory already exists (and create one when it isn’t)

In my case, the location is in D:\programs\MySQL\MySQL Server 8.0\data, so I need to make sure the data/ folder exists in that path.

You may have a different path depending on your configurations during MySQL installation.

Once you created the data/ folder, you can try starting the MySQL server again.

To sum it up, the can't create test file is not an actual error since it’s marked with a [WARNING] sign in the console.

But the warning usually means you may have a problem with MySQL datadir folder configuration.

You need to check the actual error message that’s marked with [ERROR] in the console to fix the issue.

Related articles:

Level up your programming skills

I'm sending out an occasional email with the latest programming tutorials. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.