Skip to content

MySQL’s --secure-file-priv option restricts the file operations performed by the server, affecting data import and export. This guide outlines how to address issues related to this setting.

What is the —secure-file-priv option

The --secure-file-priv option in MySQL is designed for security, limiting the directories where MySQL can read and write files. When this option is enabled, it restricts the LOAD DATA INFILE and SELECT ... INTO OUTFILE commands to specific directories or disables them entirely.

Check the current —secure-file-priv setting

To view the current setting of --secure-file-priv, you can execute the following SQL query in your MySQL client:

SHOW VARIABLES LIKE 'secure_file_priv';

This query returns the path set for the option or an empty value if it’s not set.

How to adjust the —secure-file-priv setting

Via configuration file

  1. Locate your MySQL configuration file (commonly my.cnf or my.ini).

  2. Under the [mysqld] section, add or modify the line: Replace path/to/your/directory with your desired path or leave it empty to disable the restriction.

    secure-file-priv="path/to/your/directory"
    
  3. Restart the MySQL server to apply changes.

Through server startup

Alternatively, you can set the --secure-file-priv option when starting the MySQL server:

mysqld --secure-file-priv=/path/to/your/directory

Replace /path/to/your/directory with the desired path or leave it blank to disable the option.

Handle file operations with —secure-file-priv

Importing data

When importing data using LOAD DATA INFILE, ensure the file resides in the directory specified by --secure-file-priv. If the option is disabled, the file can be located in any directory.

Exporting Data

For SELECT ... INTO OUTFILE, the output file must be located in the --secure-file-priv specified directory. If no directory is set, this operation might be restricted.

Common Troubleshooting

  • Permission Issues: Ensure the MySQL server has read/write permissions for the -secure-file-priv specified directory.
  • Incorrect Path: Verify the path set for -secure-file-priv is correct and accessible by the MySQL server.
  • Server Restart: Remember to restart the MySQL server after making changes to the configuration file.

During troubleshooting, Basedash helps teams move faster by combining AI-assisted analysis with direct SQL access, so you can validate fixes, monitor results, and share clear dashboards after incidents are resolved.

Written by

Robert Cooper avatar

Robert Cooper

Senior Engineer at Basedash

Robert Cooper is a senior engineer at Basedash who builds full-stack product systems across SQL data infrastructure, APIs, and frontend architecture. His work focuses on application performance, developer velocity, and reliable self-hosted workflows that make data operations easier for teams at scale.

View full author profile →

Looking for an AI-native BI tool?

Basedash lets you build charts, dashboards, and reports in seconds using all your data.