Skip to content

Database audit fix · Least-Privilege Permissions

How to Configure secure_file_priv in MySQL Server

MySQL's secure_file_priv decides where the server may read and write files, and an empty value leaves LOAD DATA INFILE and SELECT INTO OUTFILE pointed at the whole filesystem. Set it to NULL or a dedicated directory and restart.

Hiren KalariyaHiren KalariyaLast reviewed mysql-file-access
CtrlOpsMySQL File Import/ExportMEDIUM

What did your audit say?

WARN · when the audit printed

secure_file_priv empty, or local_infile ON

Either server-side file operations are unconfined, or the server can ask a client to hand over a local file, and the message says which.

Severity
Medium
Needs root or sudo
Yes
Results it can return
WARN · SKIP · PASS
Check in this audit
3 of 6

Every threshold on this page is transcribed from the database-security-least-privilege audit script that CtrlOps runs, and a build check fails if the two ever disagree. See all 6 Least-Privilege Permissions checks, or how the audit runs.

The check reads two live server variables: SHOW VARIABLES LIKE 'secure_file_priv', keeping the whole row so that a missing row stays distinguishable from an empty value, and SELECT @@local_infile. No row at all means the query failed and the result is SKIP, an empty value means file access is unrestricted and warns, NULL means import and export are disabled entirely, and an explicit path means they are confined to that directory, the last two both passing. local_infile is then applied on top: if it reads 1 or ON the result is forced to WARN regardless of what secure_file_priv holds.

Runs only when MySQL/MariaDB is detected and reachable as root over the socket (MYOK=1); otherwise SKIP. It reads two live server variables, so it reflects the running configuration rather than the config file. The script deliberately keeps the whole SHOW VARIABLES row: an empty value means unrestricted (WARN), whereas no row at all means the query failed and produces SKIP rather than a false finding. local_infile being ON forces WARN regardless of how secure_file_priv is set. Note secure_file_priv is read-only at runtime - a change needs a server restart before this check will see it.

What each result means
ResultWhenWhat it means
SKIPCould not read secure_file_privNothing was verified. The variable query returned no row, so the file-access setting is unknown rather than safe.
WARNsecure_file_priv empty, or local_infile ONEither server-side file operations are unconfined, or the server can ask a client to hand over a local file, and the message says which.
PASSNULL or a directory, with local_infile OFFFile import and export are blocked outright or confined to one directory, and no client-side file reads are on offer.

secure_file_priv limits where FILE operations can read/write. NULL disables them; a directory confines them. local_infile enables LOAD DATA LOCAL, where the server asks the client to send a file: a malicious or compromised server (or an injected query on a server reached by a vulnerable client) can read files from the client machine. MySQL 8 defaults local_infile=OFF. CIS MySQL "Ensure 'secure_file_priv' is not empty" and "Ensure 'local_infile' is disabled".

  • MySQL 8 packages default secure_file_priv=/var/lib/mysql-files (PASS). MariaDB defaults to empty (WARN) unless set.
  • ETL pipelines that use LOAD DATA LOCAL need local_infile on both sides; prefer LOAD DATA from the secure_file_priv directory, or enable it only for the session/client that needs it.
  • secure_file_priv is read-only at runtime; changing it needs a restart.
ini
[mysqld]secure_file_priv = NULL        # or a dedicated directorylocal_infile = 0

Restart the server.

sh
sudo mysql -N -e "SHOW VARIABLES LIKE 'secure_file_priv'"# expected: a value of NULL, or a dedicated directory such as /var/lib/mysql-filessudo mysql -N -e 'SELECT @@local_infile'# expected: 0# Prove export is confined:sudo mysql -e "SELECT 1 INTO OUTFILE '/tmp/x'"# expected: ERROR 1290 (--secure-file-priv option ... )

Debugging

  • MYOK=0; see the Authentication debugging notes.
  • The SHOW VARIABLES query returned no row at all. This is deliberate: the script refuses to report "unrestricted" when it simply could not read the value. Run the first command above by hand to see the real error (usually a permissions or connection problem, not a configuration one).
  • It is read-only at runtime, so the change only takes effect after systemctl restart mysql. Confirm the live value with the command above, not the config file.
  • Then local_infile is ON, which forces WARN on its own. sudo mysql -N -e 'SELECT @@local_infile'; set local_infile=0 in [mysqld] and restart.
  • Expected. MySQL 8 packages default to /var/lib/mysql-files; MariaDB defaults to empty (unrestricted) unless you set it. This is a real difference, not a check artefact.
  • LOAD DATA LOCAL needs it on both client and server. Prefer server-side LOAD DATA from the secure_file_priv directory, or enable the option for just the client session that needs it rather than globally.

Sources

Next

Re-run the Least-Privilege Permissions audit after applying the fix and confirm this check moves to PASS. CtrlOps runs all 6 checks over your existing SSH connection and scores the result, so the change is visible without reading another config file.

14-day free trial, no credit card required.

Explore article with AI tools

Written by

Hiren Kalariya

Co-Founder & CEO, TST Technology

Hiren Kalariya is the Co-Founder and CEO of TST Technology and the product lead behind CtrlOps, a local-first desktop app that makes Linux server management fast and easy for developers and DevOps teams. Over the past five years he has shipped 60+ production systems, and he still tests every tool he writes about on real servers.

Stop juggling tools. Start managing fleets.

PuTTY
Termius
MobaXterm
WinSCP
SecureCRT
Royal TS
Warp
CtrlOps14 tools left
Webmin
aaPanel
RunCloud
Dokploy
IP spreadsheet
bash (2)
sticky notes

One app. All your servers. No context switching. Free to start, free to leave.

Start instantly · No credit card · Cancel anytime

Your privacy preferences. We use product analytics to improve CtrlOps. Google measurement runs without analytics cookies. Live chat stays off until you allow it. Cookie policy