LOAD DATA LOCAL INFILE报2068错误排查(已开启local_infile)
Hey there, let's work through this frustrating access error you're getting with LOAD DATA LOCAL INFILE. You've already checked that local_infile is set to ON, which is a great first step—let's dive into the other common fixes that usually resolve this issue:
1. Ensure Your Client Enables Local INFILE Support
Most MySQL clients don't enable local file loading by default, even if the server has local_infile=ON:
- Command Line: When connecting, add the
--local-infile=1flag:mysql --user=your_username --password=your_password --local-infile=1 your_database_name - MySQL Workbench: Go to your connection settings, under the "Advanced" tab, find and check the
Enable local INFILEoption, then reconnect. - Other Clients: Look for a setting labeled "Allow local file imports" or similar in your client's configuration.
2. Fix Windows File Path Escaping
On Windows, backslashes (\) in file paths need to be escaped (doubled) or replaced with forward slashes (/), since MySQL interprets single backslashes as escape characters. Your path should look like one of these:
LOAD DATA LOCAL INFILE 'C:\\Users\\amanda.ramos\\Desktop\\EdX_Enrollment.csv' INTO TABLE records -- OR LOAD DATA LOCAL INFILE 'C:/Users/amanda.ramos/Desktop/EdX_Enrollment.csv' INTO TABLE records
3. Verify File Permissions for the MySQL Service
The user account running the MySQL service needs read access to your CSV file:
- Right-click the
EdX_Enrollment.csvfile → Properties → Security tab. - Click Edit → Add to include the MySQL service user (often
Local Systemor a dedicatedMySQLuser). - Grant the user Read permissions and save changes.
4. Check Both Server and Client Configuration in my.ini/my.cnf
Even if SHOW GLOBAL VARIABLES LIKE 'local_infile' returns ON, make sure your MySQL config file (my.ini on Windows, my.cnf on Linux) enables local infile for both server and client sections:
[mysqld] local_infile=ON [client] local_infile=ON
After making changes, restart the MySQL service to apply them.
5. Rule Out Firewall/Antivirus Interception
Some security tools block MySQL from accessing local files. Temporarily disable your antivirus or firewall (just for testing) to see if that resolves the issue. If it does, add MySQL to your security tool's trusted applications list.
Start with checking the client setting and path escaping first—those are the most frequent causes of this error. Let me know if any of these steps get you past the restriction!
内容的提问来源于stack exchange,提问作者Amanda Ramos

