Write rows to a server-side file.
Section: imports, exports, and mysql shell utilities
Export query results to CSV-like output
sql
sql
SELECT id, email
INTO OUTFILE '/var/lib/mysql-files/users.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM users;Explanation
Requires file privileges and uses a path writable by the server.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing imports, exports, and mysql shell utilities
Import delimited text with mysqlimport
Use the mysqlimport command-line utility.
Dump an instance with MySQL Shell
Use MySQL Shell utilities for scalable dumps.