CSV Database Backup Using Command Line
To generate a plaintext backup of a MySQL database as a CSV file, consider the following command line methods:
Method 1: Using the -B Option
This option outputs TSV (tab-separated) files that can be imported into various applications, such as Excel.
% echo 'SELECT * FROM table' | mysql -B -uxxx -pyyy database
Method 2: Using SELECT INTO OUTFILE
If you have direct server file system access, SELECT INTO OUTFILE allows you to create CSV files with specific formatting options:
SELECT * INTO OUTFILE 'table.csv' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n' FROM table
In this approach, you can customize field terminators, enclosure, and line terminators as needed.
The above is the detailed content of How to Back Up a MySQL Database as a CSV File Using the Command Line?. For more information, please follow other related articles on the PHP Chinese website!