MariaDB Select Into Outfile File Privilege Docs
To write query results to a server disk, you must grant a global file permission. The mariadb select into outfile file privilege docs explain that users also need table read rights. Most teams set up this rule when they need fast data exports for reports. Still, this permission applies to the entire server, not just one database. When you grant broad rights, any user with that role can read or write server files. This creates a major risk if an attacker steals a database password. How the mari
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
To write query results to a server disk, you must grant a global file permission. The mariadb select into outfile file privilege docs explain that users also need table read rights. Most teams set up this rule when they need fast data exports for reports. Still, this permission applies to the entire server, not just one database. When you grant broad rights, any user with that role can read or write server files. This creates a major risk if an attacker steals a database password.
How the mariadb select into outfile file privilege docs define file exports
In MariaDB, exporting query rows to a text file happens on the database host itself. When a user runs an export query, the database engine creates a new file on disk. The engine writes the selected rows directly into that target folder. Because this action touches the host operating system, MariaDB treats it as a high-trust operation. Standard table roles cannot run this command on their own.
An admin must grant the global file permission to the specific database user account first. You cannot scope this permission down to a single schema or table. It is an all-or-nothing setting across the entire database instance. Also, the operating system account that runs the MariaDB process needs folder write rights. If the operating system blocks the folder, the query fails even with database permissions in place.
MariaDB also refuses to overwrite any file that already exists in the target folder. This rule stops users from replacing system files or database logs by mistake. Admins can also set up a server path rule to limit where files go. When you set that path rule, the database only writes files inside that one approved folder. If a user tries to write to another disk path, the engine blocks the query.
Security risks of server file permissions
Granting the global file permission solves the basic need for fast bulk data exports. Yet it leaves a large security gap open during daily operations. The native permission only checks who logs in and whether they hold the global right. It does not inspect what specific data the query pulls in flight.
Also, the same global file permission allows users to read local files from the server disk. A user with this right can load server text files straight into a database table. If the MariaDB system account can read a host file, the database user can too. This means a user might read sensitive app settings or key files stored on the host.
Least Privilege Principle + Lock File Integrity: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Even if you restrict the export folder path, sensitive customer data can still leak out. A developer running a valid export query will pull raw emails, phone numbers, and card numbers. Those sensitive fields then sit in plain text on the host disk. Native roles cannot rewrite or mask those fields while the query runs. Teams often share one admin account for exports, which makes tracking who ran what impossible.
Safer ways to handle data exports
To reduce risk, teams should avoid granting global file rights to normal user accounts. Instead of writing files on the database host, run queries from a client tool. This approach pulls rows over the network without needing host disk permissions at all. You can then apply data masking rules in flight to rewrite emails and national IDs.
When a host export is required, teams should require peer approval before the query runs. Logging every single query tied to a real person also helps security teams audit file exports. By inspecting queries before they hit the server, you stop bad file writes early.
Check MySQL queries and results on the wire
MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL. It runs next to MySQL, RDS, or Aurora and reads the MySQL wire protocol.
Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails. When a rule refuses a query, MySQL returns a native error packet with your message. On the response path, hoop.dev data masking rewrites string values in returned rows that match your rules. Every query and decision is logged per resource. See the MIT-licensed project on GitHub.
Frequently asked questions
Why does my export query fail even after I grant the file permission?
The operating system user running MariaDB likely lacks write permissions for that disk folder. You must also check if a server path rule restricts exports to one specific directory. Finally, make sure a file with the exact same name does not already exist there.
Can I grant the file permission to just one single database or table?
No, MariaDB only allows you to grant the file permission at the global server level. Once a user has this right, they can export data from any table they can read. To limit what they export, you must restrict their read permissions on the tables instead.
Does the export command save the output file to my local computer?
No, the database engine always writes the output file directly onto the database server disk. It never sends the file across the network to your local client machine. If you need a local file, run a standard query and save the output locally.
Related guides
In this post