Skip to content

Databases

local_infile, probably off

Why we keep local_infile disabled for normal hosting and when a brief VPS exception might make sense.

Updated Aug 29, 20263 min read10 reads
local_infile, probably off
Why local_infile stays off on most accounts

local_infile is a MySQL setting that lets a client push a file from its own machine into a table with LOAD DATA LOCAL INFILE. On shared hosting and most web apps it should stay off, because a bug or injected query can turn that path into a way to read or plant files. WordPress does not need it, and a CSV plugin is not a good reason to enable it.

What has to line up for a load

Three pieces must agree before a local load works. The server variable local_infile must allow it. The client or library must send the LOCAL flag. The SQL statement must name a path the client can see. If the server setting is off, the statement fails cleanly. If the server is on and the client is PHP behind a site, a mistake in the app can ask MySQL to touch files the web user can reach. That is why we treat a plugin “enable remote CSV” checkbox as a security risk dressed up as a feature.

Shared hosting versus a one-off on VPS

On shared hosting, local_infile is off on purpose. You do not get root, and you cannot flip the global for one site. phpMyAdmin already imports CSV through the panel’s upload path and then inserts rows under its own rules, so you do not need the client-side LOCAL path. On a VPS you control, you may turn it on for a single session, load a file from a path you trust, then turn it off again. Do not leave it enabled in my.cnf for months because a tutorial said Magento or a custom importer needed it.

Safer ways to import data

Prefer ordinary INSERT statements, or a server-side file under a directory you own and lock down, instead of leaving LOCAL open for the web stack. After any temporary change on a VPS, confirm the setting with a simple check so you know it is back off.

code
SHOW VARIABLES LIKE ‘local_infile’;

If a guide told you to set it ON globally so an importer could read a CSV, rewrite that importer and leave the variable off. When the job is export rather than import, use careful dump options instead of copying risky defaults. See mysqldump flags that save you for that side of the work.

Share

Send this article

Need someone else to do this? Send them the link — the commands are in the article.

Was this article helpful?

Be the first to rate this article.