Use SELECT ... INTO OUTFILE or mariadb-dump --tab to write table rows to a comma-separated text file.
CSV is the quickest bridge between MariaDB and spreadsheets, BI tools, or external services. It preserves rows, keeps costs low, and loads instantly.
Run SELECT ... INTO OUTFILE inside MariaDB.The server streams the result set directly to a file on the database host—no client bandwidth required.
It executes a normal SELECT but redirects rows to a file path defined by secure_file_priv or any writable directory if secure_file_priv is empty.
Use FIELDS TERMINATED BY, ENCLOSED BY, and LINES TERMINATED BY to define separators, quotes, and line endings that downstream tools expect.
1. Confirm secure_file_priv with SHOW VARIABLES. 2.Choose a writable path, e.g., /var/lib/mysql-files. 3. Run the example query below. 4. Copy the .csv file to your workstation.
Add a WHERE clause (e.g., WHERE created_at > CURRENT_DATE - INTERVAL 1 DAY).You still use INTO OUTFILE; only qualifying rows get written.
Yes—schedule the statement in a cron job that calls mariadb -e "..." or use the MariaDB Event Scheduler for server-side automation.
Export in chunks with LIMIT/OFFSET or primary-key ranges to avoid table locks and oversized files.Compress files afterward with gzip to save disk.
• Grant FILE privilege only to service accounts that need exports.
• Keep exports under /var/lib/mysql-files to respect secure_file_priv.
• Always set ENCLOSED BY '"' to protect embedded commas.
mariadb-dump --tab writes a .sql and .txt pair per table; the .txt file is ready-made CSV when you combine --fields-terminated-by and --fields-enclosed-by parameters.
Check that the SELECT actually returns rows and that the server user owns the target directory.Review error log entries for file-path denials.
.
No. It fails with “File exists” to prevent accidental data loss. Delete or rename the old file first.
Run a separate SELECT ... INTO OUTFILE for each table or use mariadb-dump --tab to dump every table in a schema.
Yes. Use the mariadb client: mariadb -h db_host -u user -p -e "SELECT ... INTO OUTFILE ...". The file is still created on the server, so copy it via scp.