MySQL cannot create, read, or write a file because the supplied path or filename contains illegal characters or violates the operating system rules.
MySQL ER_WRONG_FILE_NAME (error 3121) means the server rejected a path or filename as invalid when running file based statements like LOAD DATA or SELECT INTO OUTFILE. Fix it by supplying an absolute path with legal characters and correct permissions.
ER_WRONG_FILE_NAME
MySQL raises ER_WRONG_FILE_NAME when it cannot create, read, or write the file specified in a statement. The server validates the supplied path against operating system rules and its own secure_file_priv setting. If any part of the path is illegal, the operation stops and this error appears.
The error was introduced in MySQL 5.7.6 and commonly surfaces during file based operations such as LOAD DATA INFILE, SELECT ... INTO OUTFILE, or when writing binary log files to disk.
The error occurs only at runtime, typically after the parser accepts the SQL. The server tries to open a file and the underlying OS rejects the request due to characters like : * ? < > | or a path outside allowed directories. SELinux, AppArmor, or Windows ACLs can also trigger the failure.
File operations often power ETL jobs, backups, and data exports. A blocked operation can stop downstream pipelines, delay analytics, or cause partial backups. Immediate correction keeps data flows reliable and prevents cron job failures.
An illegal character in the filename is the most frequent cause. Windows disallows characters that Unix allows, and vice versa, which bites when scripts run on multiple platforms.
Using a relative path that the secure_file_priv sandbox rejects will also trigger ER_WRONG_FILE_NAME. If secure_file_priv is set, only paths inside that directory are legal.
Mis-configured container mounts or read-only volumes can corrupt the final path, leaving stray quotes or newline characters that MySQL rejects as invalid.
Validate the filename manually first. Remove spaces, tabs, control characters, and any of : * ? < > | / depending on platform. Stick to alphanumerics, underscores, and dots.
When secure_file_priv is set, move the file into that directory or disable the setting for the session if security policy allows.
Use an absolute path to avoid ambiguity and shell expansion problems in automated scripts.
Scenario: LOAD DATA INFILE fails during import.
Solution: Confirm the local file exists within secure_file_priv, rename it to a safe name like import_2024_04_12.csv, and rerun the statement.
Scenario: SELECT INTO OUTFILE fails in a cron job after a server upgrade.
Solution: Check whether MySQL 8.0 enabled secure_file_priv by default in your configuration file and update the export path accordingly.
Adopt a naming convention limited to letters, numbers, underscores, hyphens, and periods. Enforce it in application code.
Store all import and export files in a dedicated directory that matches secure_file_priv and version-control the setting in your my.cnf.
In CI pipelines, run a quick OS-level validation of filenames before calling MySQL to catch issues earlier.
ERROR 1290 secure_file_priv - Indicates the path violates the secure_file_priv sandbox. Fix by adjusting the path or configuration.
ERROR 1045 Access denied - Permissions issue opening the file. Ensure the MySQL user or OS process can read or write the path.
ERROR 1158 Got an error reading communication packets - Network or file permission errors during LOAD DATA LOCAL INFILE can mislead logs. Double-check filenames first.
Characters like : * ? < > | are illegal on Windows and rejected by MySQL before the OS call completes.
When secure_file_priv is set, any path outside the configured directory triggers ER_WRONG_FILE_NAME.
Extra quotes, backticks, or newline characters inserted by dynamic SQL can corrupt the filename.
On case-sensitive filesystems, a wrong case in directory names leads MySQL to open a non-existent path and emit the error.
Thrown when the supplied path is outside the sandbox. Fix by moving files or changing configuration.
Indicates permission issues rather than filename issues. Grant proper file privileges on the OS.
MySQL tried to open a valid name but the file does not exist. Verify the path and file creation logic.
Yes, but only if your security policy allows it. Set secure_file_priv to an empty string in my.cnf or with SET GLOBAL, then restart or re-connect.
The LOCAL variant bypasses secure_file_priv but still validates the filename. Illegal characters will still trigger the error.
Newer versions tighten filename validation rules and enable secure_file_priv by default. Update scripts to comply with stricter checks.
Galaxy flags unsafe characters as you type and autocompletes valid paths from your server metadata, reducing the chance of an invalid filename.