MySQL Failed to Open File Error 2: Check Path, LOCAL and secure_file_priv

When MySQL reports a file-not-found error with Errcode 2, first determine which machine is expected to read the file. `INFILE` and `LOCAL INFILE` do not use the same path context.

MySQLMySQL 8.x · Linux · WindowsLast reviewed Sep 25, 2026
🎯 You’re likely in the right place if:
The error includes “File … not found”, “Failed to open file”, or Errcode 2.The failing operation reads an external file, such as LOAD DATA, LOAD XML or LOAD_FILE().The file exists somewhere, but MySQL still cannot open it from the path in the statement.
Difficulty: ModerateRisk: Low first
🔎 Quick Check — inspect MySQL file restrictions

Check the server’s file-import directory and whether LOCAL loading is enabled before moving files or changing permissions.

SELECT @@secure_file_priv, @@local_infile;

Verify: You know whether server-side file access is restricted to a specific directory and whether LOCAL loading is available.

Did this check explain the file location MySQL expects?
ADSENSE · reserved slot after the first useful step

Why this happens

For server-side file operations, MySQL resolves the file on the database server host. With `LOCAL`, the client reads the file and sends it to the server. A correct-looking path can therefore point to the wrong machine. MySQL can also restrict server-side import/export paths with `secure_file_priv`.

Diagnose before changing more

1
Are you using INFILE or LOCAL INFILE?
Without LOCAL, the server must be able to see the file. With LOCAL, the client process must be able to read it.
2
What does secure_file_priv return?
A directory value restricts server-side import/export to that directory; NULL disables those operations.
3
Does the exact path exist for the process that reads it?
Use an absolute path and verify spelling, case and permissions on the correct host.

Fix #2 — use the correct server or client path

If the statement is server-side, place the file in an allowed server directory and reference the server’s path. If you intentionally need client-side loading, use `LOCAL` only when both the client and server permit it.

LOAD DATA LOCAL INFILE '/absolute/client/path/file.csv' INTO TABLE your_table;
🟡 Before changing configuration: Only use LOCAL when it matches your security requirements; it changes which side reads the file.
Did Fix #2 work?

Fix #3 — respect secure_file_priv instead of disabling it

If `@@secure_file_priv` names a directory, move or copy the import file there and ensure the MySQL server account can read it. Avoid weakening `secure_file_priv` globally just to make one import succeed.

SHOW VARIABLES LIKE 'secure_file_priv';
🟡 Keep it reversible: File privileges are security-sensitive. Prefer the configured import directory and least privilege.
Did Fix #3 work?

Still seeing the error?

If the file is in the correct location but error 2 remains, compare the exact path MySQL reports with the real path, including letter case on case-sensitive file systems. Then check operating-system permissions for the client or server process that is actually opening the file.

Official references

Still stuck? Ask the community

Share your operating system, software version, exact error text, and which fix you already tried. Another reader may have seen the same setup.

Keep it safe: never post passwords, API keys, access tokens, recovery codes, license keys, private URLs, or confidential logs.
Powered by GitHub DiscussionsSign in with GitHub to comment. Reading comments does not require sign-in.

Loading community discussion…