So Murakami - BlogTroubleshooting MySQL Error 1290: Resolving the --secure-file-priv Option

Updated: May 01, 2024

Published: May 01, 2024

Title Image

Introduction

MySQL, a popular open-source relational database management system, implements various security measures to safeguard data. One such measure is the --secure-file-priv option, which limits file operations to specific directories, preventing unauthorized access and potential security breaches. However, this security feature can sometimes pose challenges, leading to Error 1290 when executing certain SQL statements, notably those involving file operations like SELECT INTO OUTFILE.


Understanding Error 1290

Error 1290 (HY000) is a MySQL error code indicating that the server is running with the --secure-file-priv option enabled, thereby restricting the execution of statements involving file operations. This error commonly occurs when attempting to export query results to an outfile using the SELECT INTO OUTFILE statement.

Diagnosing the Issue

To diagnose the cause of Error 1290 and determine the permitted directory for file operations, the following SQL command can be executed:

SHOW VARIABLES LIKE "secure_file_priv";

This command retrieves the value of the secure_file_priv system variable, revealing the directory permitted for file operations by MySQL.

Resolving Error 1290

Once the permitted directory is identified, resolving Error 1290 involves either adjusting the secure_file_priv variable to allow the desired directory or relocating the file operations to the permitted directory.

  • Adjusting secure_file_priv Variable: If the current directory specified in secure_file_priv does not meet the requirements of your file operations, you can modify the variable to include the desired directory. This can be done by updating the MySQL configuration file (my.cnf or my.ini) and restarting the MySQL server.Example
secure-file-priv = /new/permitted/directory
  • Relocating File Operations: Alternatively, if modifying the secure_file_priv variable is not feasible or desirable, you can relocate the file operations to the permitted directory specified by secure_file_priv.

Example:

SELECT * INTO OUTFILE '/permitted/directory/file_name' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' FROM yourdatabase WHERE created_at BETWEEN NOW() - INTERVAL 30 DAY AND NOW();

Conclusion

MySQL Error 1290, stemming from the --secure-file-priv option, can hinder file operations within the database. By understanding the cause of this error and following the steps outlined in this guide, users can effectively diagnose and resolve Error 1290, ensuring smooth execution of SQL statements involving file operations in MySQL environments.

@2025