Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

Error 2068: the client rejected your LOAD DATA LOCAL INFILE file

ErrorERROR 2068 (HY000): LOAD DATA LOCAL INFILE file request rejected due to restrictions on access.

Short answer

Error 2068 is raised by the client library. Local loading is switched off there, and the only exception is the directory set with --load-data-local-dir (or MYSQL_OPT_LOAD_DATA_LOCAL_DIR). A file outside that directory, an empty directory value, or a path that differs in letter case is turned away. Enable local loading or use the right path.

  • Applies to MySQL 8.0, MySQL 8.4 LTS, mysql client 8.4
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Find out how the client was started. Look for --local-infile and --load-data-local-dir in the command, in the option files, or in the program's connection settings.

    grep -R -n -E "local-infile|load-data-local-dir" ~/.my.cnf /etc/my.cnf /etc/mysql/ 2>/dev/null
  2. 2Match what you see, then jump to its fix

    1. 1The client runs with --local-infile=0, a library default of off, or --load-data-local-dir pointing somewhere else.Local loading is off and the file is outside the permitted directoryFix
    2. 2--load-data-local-dir is set and the file looks like it is inside, for example /Data versus /data.The file path differs from the permitted directory in letter caseFix

What does the error look like?

  • ERROR 2068 (HY000): LOAD DATA LOCAL INFILE file request rejected due to restrictions on access.

Cause 1 of 2

Local loading is off and the file is outside the permitted directory

1Check

When LOCAL loading is disabled, --load-data-local-dir names the one directory local files may come from. Left empty (the default), it names no directory, so no file is permitted. If LOCAL loading is enabled, the option is ignored.

grep -R -n -E "local-infile|load-data-local-dir" ~/.my.cnf /etc/my.cnf /etc/mysql/ 2>/dev/null

2Fix

Either move the file into the permitted directory, or start the client with local loading enabled. The server must allow it too.

mysql --local-infile=1 -u app -p mydb

-- on the server, if the variable is OFF:
SET GLOBAL local_infile = 1;

3Verify

Run the same LOAD DATA LOCAL INFILE statement again.

LOAD DATA LOCAL INFILE '/home/me/data/users.csv' INTO TABLE users FIELDS TERMINATED BY ',';

Confirmed by dev.mysql.com

Did this fix it?

Cause 2 of 2

The file path differs from the permitted directory in letter case

1Check

The directory path and the file path are compared case-sensitively, whatever the file system's own rules are. On a case-insensitive disk the file opens in the shell but the comparison still fails.

grep -R -n "load-data-local-dir" ~/.my.cnf /etc/my.cnf /etc/mysql/ 2>/dev/null

2Fix

Write the file path with exactly the same letters as the directory in the option.

mysql --local-infile=0 --load-data-local-dir=/my/local/data -u app -p mydb
-- then load /my/local/data/users.csv, not /My/Local/Data/users.csv

3Verify

The statement completes and reports the rows loaded.

SELECT COUNT(*) FROM users;

Confirmed by dev.mysql.com

Did this fix it?

How do I stop it coming back?

  • Prefer a restricted directory (--load-data-local-dir) over enabling LOCAL for everything.
  • Keep import files in one fixed folder and quote the same path in scripts.
  • Remember that the server also has to allow LOCAL loading, or error 3950 follows.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.