MySQL's `SELECT ... INTO OUTFILE` command lets you quickly dump the results of a MySQL query into a file on the MySQL server. It generally should not be used for production use.
MySQL's SELECT ... INTO OUTFILE
command lets you quickly dump the results of a MySQL query into a file on the MySQL server. It generally should not be used for production use.
From the MySQL documentation
The
SELECT ... INTO OUTFILE 'file_name'
form of SELECT writes the selected rows to a file. The file is created on the server host, so you must have the FILE privilege to use this syntax. file_name cannot be an existing file, which among other things prevents files such as /etc/passwd and database tables from being destroyed.
One must be able have access to the MySQL server machine, and permissions to operate on files as the mysql
user in order to access and manage the dump files. These restrictions mean the SELECT ... INTO OUTFILE
command is generally suitable only for testing and debugging.
If you want a dump of a table from a MySQL database on your client machine, you can call the mysqldump
binary on the client. If you want a CSV of the results of a MySQL query, you generally need to roll your own code to create that file in your client application, though there are libraries that can help with the CSV format.