Home > Database > Mysql Tutorial > body text

How to Back Up a MySQL Database as a CSV File Using the Command Line?

DDD
Release: 2024-10-30 20:12:02
Original
412 people have browsed it

How to Back Up a MySQL Database as a CSV File Using the Command Line?

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
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!