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.
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.
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
Without LOCAL, the server must be able to see the file. With LOCAL, the client process must be able to read it.
A directory value restricts server-side import/export to that directory; NULL disables those operations.
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;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';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.
Loading community discussion…
Comments could not load here. Open ErrorHarbor Discussions on GitHub →